I'm having difficulty understanding what impacts the "rendered" attribute has on form fields and was hoping somebody could clarify the behavior for me.
Lets say I have the JSF example code below. It has 1) A top-level menu, 2) A form submit button, 3) A conditionally rendered sub-menu, 4) A conditionally rendered output text. The idea is that the user selects an item from the first menu, submits - and then is presented with another menu, submits, then is presented with some text. In this case options 'B' and '2' should result in the text being displayed.
<h:form styleClass="form" id="form1">
<h:selectOneMenu styleClass="selectOneMenu" id="menu"
value="#{PlayBean.menuChoice}">
<f:selectItem itemLabel="choiceA" itemValue="A" />
<f:selectItem itemLabel="choiceB" itemValue="B" />
<f:selectItem itemLabel="choiceC" itemValue="C" />
</h:selectOneMenu>
<br />
<br />
<h:panelGrid id="subMenuGrid" rendered="#{PlayBean.menuChoice == 'B'}">
<h:selectOneMenu styleClass="selectOneMenu" id="submenu"
value="#{PlayBean.subChoice}">
<f:selectItem itemLabel="subChoice1" itemValue="1" />
<f:selectItem itemLabel="subChoice2" itemValue="2" />
<f:selectItem itemLabel="subChoice3" itemValue="3" />
</h:selectOneMenu>
</h:panelGrid>
<h:panelGrid id="outputGrid" rendered="#{PlayBean.subChoice == '2'}">
<h:outputText value="You made it!" />
</h:panelGrid>
<h:commandButton type="submit" value="Submit" styleClass="commandButton" id="button1"
action="#{PlayBean.doPlay}"></h:commandButton>
</h:form>
When I run this JSF example the value for PlayBean.subChoice is never saved in the backing bean - resulting in the outputGrid panel never rendering. I was able to get this to work by switching the bean scope to "session", however I don't understand why this works - and I would prefer to stay in request scope. By using a PhaseListener I can dump the external context request parameter map and I can see that the sub-menu form field was properly submitted to the web container.
Why doesn't the PlayBean.subChoice setter method get invoked on the backing bean during the update model phase?
Why does switching to session scope for the bean make this work?
I've tried this on Sun's 1.1 implementation and on MyFaces 1.2 with the same result.