I'll be very pleased to get a decent explaination for the following case.
Here's a simple JSF with two forms and text output:
<h:body>
<h:form>
<h:commandButton value="Go" action="#{wierdBean.doWierdStuff}"/>
</h:form>
<h:form>
<h:dataTable value="#{wierdBean.pages}" var="page">
<h:column>
<h:commandButton value="the same go action?" action="#{wierdBean.doWierdStuff}"/>
</h:column>
</h:dataTable>
</h:form>
</h:body>
<h:dataTable value="#{wierdBean.pages}" var="page">
<h:column>
<h:outputText value="#{page}"/>
</h:column>
</h:dataTable>
'Go' button at the top is supposed to do the same thing as the 'the same go action?' buttons.
Backing WierdBean is:
public class WierdBean implements Serializable {
private int buttonsCount;
public WierdBean() {
System.out.println("WierdBean()");
}
@PostConstruct
public void postConstruct() {
System.out.println("postConstruct()");
}
public Integer[] getPages() {
System.out.print("getPages() buttonsCount(): " + buttonsCount);
Integer[] pages = new Integer[buttonsCount];
for (int i = 0; i < pages.length; i++) {
pages[i] = new Integer(i);
}
return pages;
}
public String doWierdStuff() {
System.out.println("doWierdStuff()");
buttonsCount = 2;
return "wierd";
}
}
When I enter the page I get:
INFO: WierdBean()
INFO: postConstruct()
INFO: getPages() buttonsCount(): 0 (16 times)
and I seen only the 'Go' button. That's understandable.
After Pressing the 'Go' button I get:
INFO: WierdBean()
INFO: postConstruct()
INFO: getPages() buttonsCount(): 0 (19 times)
INFO: doWierdStuff()
INFO: getPages() buttonsCount(): 2 (16 times)
Nice, doWierdStuff is called and then I get 2 'the same go action' buttons and 2 text outputs. That's fine.
However, when I press any of the the 'the same action' buttons, which are supposed to do the same thing as 'Go' button - call the doWierdStuff method - I get:
INFO: WierdBean()
INFO: postConstruct()
INFO: getPages() buttonsCount(): 0 (44 times)
There is only 'Go' button visible.
Why is that?