valueChangeListener不使用PrimeFaces selectOneRadio

时间:2013-06-07 11:38:07

标签: ajax jsf jsf-2 primefaces selectoneradio

我在valueChangeListener的主要面上放置selectOneRadio,根据所选内容在页面上呈现一些组件,但它不起作用

<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页面中的组件,它们将根据布尔值femalemale

的值进行呈现
    <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>

当我将radioButton更改为女性时,语句Fired将在控制台中打印,但上面的组件未呈现

2 个答案:

答案 0 :(得分:0)

一些事情:

1)如果您需要知道旧值和新值,则只需要使用valuechange侦听器。如果您只是渲染组件,请使用:

 <f:ajax execute="@this" listener="#{personBean.triggerGender}" render="triggerGender"></f:ajax>

2)如果你想要ajax刷新它,你的表单中需要有一个id为'triggerGender'的组件

3)您的单选按钮组件绑定到#{someBean.booleanVariable},但是您选择的项目的项目值是字符串。它们不应该是真或假的布尔吗?

4)你的输出标签应该基于#{someBean.booleanVariable}有条件地呈现,并且应该在id为'triggerGender'的组件中

答案 1 :(得分:0)

您应该在h:panelGroup中嵌套表单并渲染PanelGroup