I have a ui repeat that contains a inputtext and command button pairs. The button simply changes the value that the inputtext displays and re-renders it. On the first button click it changes the value but does not re-render on the screen. The second click does the same but successfully re-renders the control. Onevent triggers all 3 status events just fine. Nothing shows in the logs either. The problem seems server side but i'm using the default faces setup from netbeans 7.3.1.
The below code will display 4 lines of inputValue and buttons. The first works fine (its outside of the ui:repeat. The 3 below all require 2 clicks.
TestBean.java
@ManagedBean
@ViewScoped
public class TestBean implements Serializable {
private MyObject nc;
private List<MyObject> list;
public TestBean() {
nc = null;
list = new ArrayList<MyObject>();
}
public MyObject getNc() {
return nc;
}
public void setNc(MyObject nc) {
this.nc = nc;
}
public List<MyObject> getList() {
return list;
}
public void setList(List<MyObject> list) {
this.list = list;
}
@PostConstruct
public void onInit() {
MyObject nc1 = new MyObject();
nc1.setText("1");
list.add(nc1);
MyObject nc2 = new MyObject();
nc2.setText("2");
list.add(nc2);
MyObject nc3 = new MyObject();
nc3.setText("3");
list.add(nc3);
MyObject nc0 = new MyObject();
nc0.setText("0");
nc = nc0;
}
}
MyObject.java
public class MyObject implements Serializable {
public String text;
public MyObject() {
this.text = "";
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public void testMethod() {
text = "HEY";
}
}
index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
Hello from Facelets<br />
<h:form>
<h:inputText id="text" readonly="true" value="#{testBean.nc.text}" />
<h:commandButton value="test">
<f:ajax listener="#{testBean.nc.testMethod()}" execute="text" render="text" />
</h:commandButton><br /><hr />
<ui:repeat value="#{testBean.list}" var="cur">
<h:panelGroup id="viewTest">
<h:inputText id="text" readonly="true" value="#{cur.text}" />
</h:panelGroup>
<h:commandButton value="test">
<f:ajax listener="#{cur.testMethod()}" render="viewTest" immediate="true" />
</h:commandButton><br />
</ui:repeat>
</h:form>
</h:body>
</html>