a4j:commandButton rerender issues
stasikos May 10, 2011 2:14 PMHere is a sample code I used to understand how to use a4j:commandButton RF4:
<?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:h="http://java.sun.com/jsf/html" xmlns:rich="http://richfaces.org/rich" xmlns:a4j="http://richfaces.org/a4j"> <h:head> <title>Facelet Title</title> </h:head> <h:body> <h:form id="topForm"> <a4j:commandButton value="Show form" oncomplete="#{rich:component('table_mp')}.show()"/> <rich:popupPanel id="table_mp" modal="true" width="370" minWidth="370" resizeable="false" autosized="false" moveable="true" > <h:form id="bugform" > <rich:dataTable id="attributes" value="#{TableController.attributes}" var="attr"> <rich:column> <h:inputText value="#{attr}" /> </rich:column> </rich:dataTable> <a4j:commandButton value="Add attribute" action="#{TableController.addAttribute()}" execute="@this" render="attributes, bugform, topForm"/> </h:form> </rich:popupPanel> </h:form> </h:body> </html>
And a controller for it:
package name.stasikos.bug; import java.util.ArrayList; import java.util.List; import javax.faces.bean.ManagedBean; /** * * @author stasikos */ @ManagedBean(name="TableController") public class TableController { private List<String> attributes = new ArrayList<String>(); public List<String> getAttributes() { return attributes; } public void setAttributes(List<String> attributes) { this.attributes = attributes; } public TableController() { this.attributes.add("Initial attr"); } public TableController(List<String> attributes) { this.attributes = attributes; } public String addAttribute() { this.attributes.add(("attributeName" + attributes.size()).toString()); System.out.println("attribute added" + System.currentTimeMillis()); System.out.println(attributes.size()); return "OK"; } }
It actually executes controller's addAttribute() method when I click "Add attribute" button and does it once. Server sends an response to request with new form contents (including added "attributeName1" item), however, new content is not displayed by browser.
The expected result was to see the same modal panel with new inputText components adding, listing every item from attributes property. I.e. user clicks "Add attribute" button and adds new text field every time. Similar approach was working with RF3, but now I'm confused about it.