0

I am trying to do a page with a few tabs, by using primefaces. But some some selected values are lost while navigating between tabs. Last tab contains 2 selectBooleanCheckboxes and 2 selectOneRadios and one of the selectoneradio grid is rendered according to checkbox value. When user selects among these 4 components and navigates between tabs radio button and check box selected values are lost. I am using @viewScoped at the bean part. For example if the user is viewing the 4th tab and wants to change something from third tab. When user navigates to the third tab and makes change on checkbox or radio button new values and previous values are reset. Form is uploading itself again I think. Why the values are lost?Is there a solution for this? Do I need something like converter?

my .xhtml is:

   <h:form id="form">
        <p:tabView id="tabPanel" dynamic="true" activeIndex="#{myBean.activeIndex}" cache="false">

            <!-- FIRST TAB -->
            <p:tab id="person" title="Person">
                <h:panelGrid columns="2" cellpadding="10">              
                    <h:outputText value="name" />
                    <p:inputText value="???USERINFO???" label="Name" />
                    <p:commandButton  value="NEXT" action="#{myBean.nextTab}" update=":form:tabPanel" />
                </h:panelGrid>
            </p:tab>                     

            <!-- SECOND TAB -->
            <p:tab id="adres" title="Address">
                <h:panelGrid columns="2" cellpadding="10">
                    <h:outputText value="Phone" />
                    <p:inputMask id="phone" value="???USERINFO???" mask="1999999999" required="true" requiredMessage="ERROR AT PHONE NUMBER"/>
                    <p:commandButton  value="NEXT" action="#{myBean.nextTab}" update=":form:tabPanel" />
                </h:panelGrid>
            </p:tab>

            <!-- THIRD TAB -->
            <p:tab id="contact" title="Contact">
                <h:panelGrid columns="2" cellpadding="10">


     <h:panelGrid columns="3" style="margin-bottom:5px" cellpadding="5">
   <h:outputText value="My Question: " />
        <p:selectBooleanCheckbox value="#{myBean.myCheckBox}" />
        <h:outputText value="Yes" />                     
        <h:outputText value="My Second Question:" />
        <p:selectBooleanCheckbox value="#{myBean.myCheckBox2}" />
        <h:outputText value="No" /> 
     </h:panelGrid>                           

     <h:panelGrid id="panelGrid" columns="3" style="margin-bottom:10px" cellpadding="10">
 <p:outputLabel value="My question"/>
  <h:outputLabel for="radio"/>
  <h:selectOneRadio id="radio" value="#{myBean.radioButton}" required="true" requiredMessage="ERROR">
      <f:selectItem itemLabel="Yes" itemValue="Yes"/>
      <f:selectItem itemLabel="No" itemValue="No"/>
    <f:ajax execute="@this" render="idInfo"/>
     </h:selectOneRadio>
     </h:panelGrid>                 

                        <h:panelGroup id="idInfo">
                        <h:panelGrid columns="3" rendered="#{myBean.radioButton == 'No'}">
                        <h:outputText value="Chooses: " />
                        <h:selectOneRadio id="selectOneRadio" value="#{myBean.type}" layout="pageDirection">
                            <f:selectItem itemLabel="Choice 1" itemValue="choice1"/>
                            <f:selectItem itemLabel="Choice 2" itemValue="choice2"/>
                            <f:selectItem itemLabel="Choice 3" itemValue="choice3"/>
                         </h:selectOneRadio>
                        </h:panelGrid>  
                        </h:panelGroup>     
                </h:panelGrid>
            </p:tab>             

        </p:tabView>
    </h:form>
xxxx
  • 27
  • 2
  • 8

1 Answers1

0
<p:commandButton  value="NEXT" action="#{myBean.nextTab}" update=":form:tabPanel" />

Add process to your button's process=":form:tabPanel" so the value is set to the property in backbean.

Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202
Dijana Cukic
  • 196
  • 1
  • 9
  • I tried this at the last tab button but did not change. – xxxx Jun 30 '16 at 14:09
  • why ajax="false"? and try process="@this :form:tabPanel" – Dijana Cukic Jun 30 '16 at 14:25
  • I tried but I get this error: 1100: Cannot find component with identifier "@this:form:tabPanel" referenced from "tabPanelInst:j_idt250". javax.faces.FacesException: Cannot find component with identifier "@this:form:tabPanel" referenced from "tabPanel:j_idt250" – xxxx Jul 01 '16 at 05:42