I have the following code in JSF-2 Mojarra 2.0.8 running on Tomcat 7
Use a simple Boolean value in your backing bean:
private Boolean choice;
// getter and setter
And in the facelet:
<h:selectOneRadio id="yesNoRadio" value ="#{user.choice}">
<f:selectItem itemValue="#{false}" itemLabel="No" />
<f:selectItem itemValue="#{true}" itemLabel="Yes"/>
<f:ajax execute="@form" render="userDetailsGrid "></f:ajax>
</h:selectOneRadio>
..
<h:panelGrid id="userDetailsGrid">
<h:panelGrid columns="2" rendered="#{user.choice}">
..
</h:panelGrid>
..
</h:panelGrid>
You can also just check the enum value in the rendered
attribute. Enums are evaluated as strings in EL, so you can do a simple string comparison. This way you can keep your original code.
<h:panelGrid columns="2" rendered="#{user.yesNoRadio == 'Yes'}">
By the way, you perhaps really want to use execute="@this"
instead of execute="@form"
(or just remove it altogether, it defaults to @this
already). The execute="@form"
will process the entire form and thus also fire validation there where you perhaps don't want.