在primefaces上呈现的表单不会调用manage bean

时间:2013-08-29 21:13:51

标签: jsf-2 primefaces glassfish-4

我遇到的问题是由PrimeFaces 3.5上的booleanButtom呈现的表单 表单按预期显示,但是当我提交时,字段的值为null。 pag的代码:`

<p:panelGrid>
     <p:row>
           <p:column>
                <h:form id="city">
                   <p:panelGrid columns="2">
                       <h:outputText value="Name: "/>
                       <p:inputText label="Name" value="#{managedBean.city.name}"/>

                       <h:outputText value="Status: "/>
                       <p:selectBooleanButton value="#{managedBean.city.status}" onLabel="Enable" offLabel="Disable">
                                  <p:ajax listener="#{managedBean.changeStatusCity()}"/>
                        </p:selectBooleanButton>

                        <h:outputText value="Add neighborhood?"/>
                        <p:selectBooleanButton id="btAddNeighborhood" value="#{managedBean.addNeighborCity}" onLabel="Cancel" offLabel="Yes">
                              <p:ajax update=":addNeighbor" listener="#{managedBean.addNeighborCity()}"/>
                        </p:selectBooleanButton>
                   </p:panelGrid>
              </h:form>
         </p:column>
     </p:row>

     <p:row>
          <p:column>
                <h:form id="addNeighbor">
                    <p:panel header="Neighborhood" rendered="#{managedBean.addNeighborCity}">
                       <p:panelGrid columns="2">
                              <h:outputText value="Name: "/>
                              <p:inputText label="Name" value="#{managedBean.neighborhood.name}"/>
                              <h:outputText value="Status: "/>
                              <p:selectBooleanButton value="#{managedBean.neighborhood.status}" onLabel="Enable" offLabel="Disable" onIcon="ui-icon-check" offIcon="ui-icon-close">
                                   <p:ajax listener="#{managedBean.changeStatusNeighbor()}"/>
                              </p:selectBooleanButton>
                       </p:panelGrid>
                    </p:panel>
                 </h:form>

                 <h:form id="formBt">
                      <p:commandButton id="bt" value="Add" actionListener="#{managedBean.saveNeighborCity()}" update=":addNeighbor, :city:btAddNeighborhood"/>
                 </h:form>
          </p:column>
     </p:row>
</p:panelGrid>`

和管理bean

public void addNeighborCity(){
    if(addNeighborCity){
        neighborhood = new Neighborhood();
        neighborhood .setStatus(true);
        neighborhood .setStringStatus("Enable");
    }else{
       neighborhood = null;
    }
}

public void changeStatusNeighbor() {
    if (neighborhood .isStatus()) {
        neighborhood .setStringStatus("Enable");
    } else {
        neighborhood .setStringStatus("Disable");
    }
}

public void saveNeighborCity(){
       city.getNeighborhoods().add(neighborhood );
       neighborhood = null;
       addNeighborCity = false;
}

呈现的表单内的所有输入都不会将信息发送到manage bean,当我将添加邻居的按钮添加到城市列表时按钮停止工作并且不调用manage豆子了。 有人知道我做错了什么或发生了什么。 我正在使用Primefaces3.5,GlassFish4.0和JSF2.2

2 个答案:

答案 0 :(得分:0)

由于您没有发布整个托管bean,我猜您正在使用托管bean的默认范围:@RequestScoped。在这种情况下,您应该使用@ViewScoped

答案 1 :(得分:0)

我解决了这个问题,我正在使用glassfish 4并且它强制jsf2.2即使你把jsf2.1放在我们的项目中,然后我改为glassfish 3并且所有工作都很好,感谢答案,并且我正在使用@ScopeSession。