0

I'm having problems with a form that is rendered by a booleanButtom on PrimeFaces 3.5 the form appear as expected but when I commit the values of the field come null. The code of the 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>`

And the manage 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;
}

All the input inside of the form that was rendered doesn't send the information to the manage bean and when I put the button that add the neighbor to the list of the city the button stop working and doesn't call the manage bean any more. Does someone knows what I'm doing wrong or what is happening. I'm using Primefaces3.5, GlassFish4.0 and JSF2.2

  • The symptoms are typical for a bean which is for the particular purpose incorrectly been placed in request scope instead of view scope. Just to exclude the obvious, is this true? Otherwise this problem is more likely to be credited to the combination PrimeFaces 3.5 and JSF 2.2. – BalusC Aug 30 '13 at 12:27

2 Answers2

0

As you did not post the whole managed bean, I guess that you're using the default scope of the managed bean: @RequestScoped. In that case you should use @ViewScoped.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
bcfurtado
  • 181
  • 2
  • 12
0

I solved the problem, I was using glassfish 4 and it forces the jsf2.2 even when you put the jsf2.1 in our project, then I changed to glassfish 3 and all work just fine, thanks for the answers, and I'm using @ScopeSession.