Dynamically adding form components with Primefaces and SWF
Hi,
Running SWF, JSF2, and Primefaces 2.2, I have a form (see below) in which I am trying to dynamically add/remove input boxes.
The add button correctly partial-updates the appropriate part of the page, but I'm having issues with the remove links. They don't seem to be able to update the page unless I do a full page refresh.
Initially I thought it was a issue with Primefaces, but after some attempts of help from the Primefaces community (see here), it appears that the problem might be on the SWF side.
From the DEBUG output (shown below), both the "add" and "remove" buttons appear to trigger the appropriate conversations, so I am really not sure where the problem is. Scope appears correct also.
Any help is greatly appreciated!
Thanks much!!
T.
.xhtml
Code:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui">
<body>
<ui:composition template="../templates/internal/BasicTemplate.xhtml">
<ui:define name="content">
<h:form>
<p:outputPanel id="authors">
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="author" value="Authors" />
<ui:repeat value="#{referenceBean.authors}" var="author" varStatus="status">
<h:inputText value="author" id="author#{status.index}" />
<p:commandLink actionListener="#{referenceBean.removeAuthor}" update="authors" >
<f:attribute name="index" value="#{status.index}" />
<h:outputText value="remove" />
</p:commandLink>
<br/>
</ui:repeat>
</h:panelGrid>
</p:outputPanel>
<p:commandLink actionListener="#{referenceBean.addAuthor}" update="authors" >
<h:outputText value="Add Author" />
</p:commandLink>
</h:form>
</ui:define>
</ui:composition>
</body>
</html>
flow
Code:
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"
parent="internal-navigation" >
<var name="referenceBean" class="backing.ReferenceBean" />
<var name="watermarkBean" class=backing.WatermarkBean" />
<view-state id="library" view="/ui/internal/library.xhtml">
<transition on="search" >
<evaluate expression="referenceBean.fillReference(remoteBiblioService.findById(referenceBean.id))" />
</transition>
</view-state>
</flow>
backing bean
Code:
/**
*
*/
package backing;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.event.ActionEvent;
import persistence.Reference;
public class ReferenceBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = -8009218053003767279L;
private List<String> authors = new ArrayList<String>();
public void fillReference(Reference ref) {
this.authors = ref.getAuthors();
}
public void setAuthors(List<String> authors) {
this.authors = authors;
}
public List<String> getAuthors() {
return authors;
}
public void addAuthor() {
authors.add("");
}
public void removeAuthor(ActionEvent e) {
String index = e.getComponent().getAttributes().get("index").toString();
int i = Integer.parseInt(index);
authors.remove(i);
}
}