I put a valueChangeListener
on a primefaces selectOneRadio
to render some components on the page according to the selected choice but it doesn't work
<p:selectOneRadio id="Gender"
value="#{someBean.booleanVariable}"
required="true"
valueChangeListener="#{personBean.triggerGender}">
<f:ajax execute="@this" listener="#{personBean.triggerGender}" render="triggerGender" />
<f:selectItem itemLabel="Female" itemValue="female" />
<f:selectItem itemLabel="Male" itemValue="male" />
</p:selectOneRadio>
personBean
public class ReportPerson {
private boolean female, male = true;
public void triggerGender(ValueChangeEvent e) {
System.err.println("Fired");
if (e.getNewValue().equals("female")) {
female = true;
male = false;
}
}
and this is the components in the JSF page that will be rendered according to the values of the booleans female
and male
<h:form id="triggerGender">
<h:outputLabel value="Does he has " styleClass="Labels"
rendered="#{personBean.male}" />
<h:outputLabel rendered="#{personBean.male}" />
<h:outputLabel rendered="#{personBean.male}" />
<h:outputLabel for="Moustache" value="Mustache ?"
styleClass="Labels" rendered="#{personBean.male}" />
<p:selectBooleanCheckbox
value="#{personBean.personDescription.moustach}"
rendered="#{personBean.male}" />
<h:outputLabel rendered="#{personBean.male}" />
<h:outputLabel value="Beared ? " styleClass="Labels"
rendered="#{personBean.male}" />
<p:selectBooleanCheckbox
value="#{personBean.personDescription.beared}"
rendered="#{personBean.male}" />
<h:outputLabel rendered="#{personBean.male}" />
<h:outputLabel value="Does she wear " styleClass="Labels"
rendered="#{personBean.female}" />
<h:outputLabel rendered="#{personBean.female}" />
<h:outputLabel rendered="#{personBean.female}" />
<h:outputLabel value="Describe?" styleClass="Labels"
rendered="#{personBean.female}" />
<p:selectBooleanCheckbox
value="#{personBean.personDescription.hijab}"
rendered="#{personBean.female}" />
<h:outputLabel rendered="#{personBean.female}" />
</h:form>
when I change the radioButton to female the statement Fired
is printed in the console but the above component isn't renderedw