我valueChangeListener
在primefacesselectOneRadio
上根据所选选项在页面上呈现一些组件,但它不起作用
<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;
}
}
这是 JSF 页面中的组件,将根据布尔值female
和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>
当我将单选按钮更改为女性时,该语句Fired
将打印在控制台中,但上述组件未呈现