Back Forum Reply New

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 quot;addquot; and quot;removequot; 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:
lt;?xml version='1.0' encoding='UTF-8' ?gt;
lt;!DOCTYPE html PUBLIC quot;-//W3C//DTD XHTML 1.0 Transitional//ENquot; quot;TR/xhtml1/DTD/xhtml1-transitional.dtdquot;gt;
lt;html xmlns=quot;1999/xhtmlquot;     xmlns:ui=quot;jsf/faceletsquot;     xmlns:h=quot;jsf/htmlquot;     xmlns:f=quot;jsf/corequot;     xmlns:p=quot;uiquot;gt;   lt;bodygt;
       lt;ui:composition template=quot;../templates/internal/BasicTemplate.xhtmlquot;gt;lt;ui:define name=quot;contentquot;gt;lt;h:formgt;   lt;putputPanel id=quot;authorsquot;gt;   lt;h:panelGrid columns=quot;2quot; cellpadding=quot;5quot;gt;      lt;hutputLabel for=quot;authorquot; value=quot;Authorsquot; /gt;      lt;ui:repeat value=quot;#{referenceBean.authors}quot; var=quot;authorquot; varStatus=quot;statusquot;gt;                           lt;h:inputText value=quot;authorquot; id=quot;author#{status.index}quot; /gt;               lt;p:commandLink  actionListener=quot;#{referenceBean.removeAuthor}quot; update=quot;authorsquot; gt;               lt;f:attribute name=quot;indexquot; value=quot;#{status.index}quot; /gt;            lt;hutputText value=quot;removequot; /gt;          lt;/p:commandLinkgt;               lt;br/gt;            lt;/ui:repeatgt;         lt;/h:panelGridgt;         lt;/putputPanelgt;           lt;p:commandLink actionListener=quot;#{referenceBean.addAuthor}quot; update=quot;authorsquot; gt;      lt;hutputText value=quot;Add Authorquot; /gt;      lt;/p:commandLinkgt;lt;/h:formgt;        lt;/ui:definegt;       lt;/ui:compositiongt;   lt;/bodygt;
lt;/htmlgt;
flow

Code:
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;
lt;flow xmlns=quot;schema/webflowquot;     xmlns:xsi=quot;2001/XMLSchema-instancequot;     xsi:schemaLocation=quot;schema/webflow     schema/webflow/spring-webflow-2.0.xsdquot;     parent=quot;internal-navigationquot; gt;        lt;var name=quot;referenceBeanquot; class=quot;backing.ReferenceBeanquot; /gt;   lt;var name=quot;watermarkBeanquot; class=backing.WatermarkBeanquot; /gt;  lt;view-state id=quot;libraryquot; view=quot;/ui/internal/library.xhtmlquot;gt;     lt;transition on=quot;searchquot; gt;        lt;evaluate expression=quot;referenceBean.fillReference(remoteBiblioService.findById(referenceBean.id))quot; /gt;     lt;/transitiongt;  lt;/view-stategt;   
lt;/flowgt;
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 Listlt;Stringgt; authors = new ArrayListlt;Stringgt;();    public void fillReference(Reference ref) {     this.authors = ref.getAuthors();  }    public void setAuthors(Listlt;Stringgt; authors) {     this.authors = authors;  }
  public Listlt;Stringgt; getAuthors() {     return authors;  }    public void addAuthor() {     authors.add(quot;quot;);  }  public void removeAuthor(ActionEvent e) {     String index = e.getComponent().getAttributes().get(quot;indexquot;).toString();     int i = Integer.parseInt(index);     authors.remove(i);  }
}
¥
Back Forum Reply New