Meaning of components lost during ajax update

I am using PrimeFaces 3.3.1 and JSF 2.0, and the server is using Oracle Weblogic 11gR1

Below is my code.

<p:panel id="personDetailsPanelId" header="#{msg.personDetails}"> <!-- Radio Button --> <h:panelGrid columns="3" style="align:center"> <h:outputText value="#{msg.accountCategory}" /> <p:spacer width="10px" /> <p:selectOneRadio id="singleJointAccountRadioId" layout="horizontal" value="#{captureAccountDetailBackingBean.accountCategory}"> <f:selectItems value="#{captureAccountDetailBackingBean.accountcategoryList}"> </f:selectItems> <p:ajax process="@this" event="change" update="@form" partialSubmit="true" /> </p:selectOneRadio> </h:panelGrid> <p:spacer height="30px;" /> <h:panelGrid id="accountDetailsId" columns="3"> <h:panelGrid id="firstAccountHolderId" columns="2" styleClass="float-left "> <p:graphicImage value="/com/cas/pages/common/images/person_icon.jpg" /> <h:outputText value="#{msg.firstAccountHolder}" /> <!-- Person Name --> <h:panelGrid columns="2"> <h:outputText value="#{msg.nameofPerson}" /> <span style="color: red;">*</span> </h:panelGrid> <p:inputText value="#{captureAccountDetailBackingBean.accountHolder1.personName}" size="25" required="true" /> <!-- Person Address --> <h:panelGrid columns="2"> <h:outputText value="#{msg.address}" /> <span style="color: red;">*</span> </h:panelGrid> <p:inputTextarea value="#{captureAccountDetailBackingBean.accountHolder1.personAddress}" rows="3" autoResize="false" required="true" /> <!-- DOB --> <h:panelGrid columns="2"> <h:outputText value="#{msg.dateOfBirth}" /> <span style="color: red;">*</span> </h:panelGrid> <p:calendar value="#{captureAccountDetailBackingBean.accountHolder1.personDOB}" navigator="true" showOn="button" size="6" required="true" pattern="dd/MM/yyyy" /> <!-- Age --> <h:panelGrid columns="2"> <h:outputText value="#{msg.age}" /> <span style="color: red;">*</span> </h:panelGrid> <p:inputText value="#{captureAccountDetailBackingBean.accountHolder1.personAge}" size="2" required="true" /> </h:panelGrid> <p:spacer width="130px;" /> <h:panelGrid id="secondAccountHolderId" columns="2" styleClass="float-left" rendered="#{captureAccountDetailBackingBean.accountCategory eq 'Joint'}"> <p:graphicImage value="/com/cas/pages/common/images/person_icon.jpg" /> <h:outputText value="#{msg.secondAccountHolder}" /> <!-- Person Name --> <h:panelGrid columns="2"> <h:outputText value="#{msg.nameofPerson}" style="font-size:15px;" /> <span style="color: red;">*</span> </h:panelGrid> <p:inputText value="#{captureAccountDetailBackingBean.accountHolder2.personName}" styleClass="inputText-style" size="25" required="true" /> <!-- Person Address --> <h:panelGrid columns="2"> <h:outputText value="#{msg.address}" /> <span style="color: red;">*</span> </h:panelGrid> <p:inputTextarea value="#{captureAccountDetailBackingBean.accountHolder2.personAddress}" rows="3" autoResize="false" styleClass="inputText-style" size="25" required="true" /> <!-- DOB --> <h:panelGrid columns="2"> <h:outputText value="#{msg.dateOfBirth}" /> <span style="color: red;">*</span> </h:panelGrid> <p:calendar value="#{captureAccountDetailBackingBean.accountHolder2.personDOB}" navigator="true" showOn="button" size="6" styleClass="inputText-style" required="true" /> <!-- Age --> <h:panelGrid columns="2"> <h:outputText value="#{msg.age}" /> <span style="color: red;">*</span> </h:panelGrid> <p:inputText value="#{captureAccountDetailBackingBean.accountHolder2.personAge}" size="2" styleClass="inputText-style" required="true" /> </h:panelGrid> </h:panelGrid> <div style="clear: both;" /> </p:panel> 

Backup bean code:

 public class CaptureAccountDetailBackingBean { // For Radio Button SelectItem[] accountcategoryList = {new SelectItem("Single", "Single"), new SelectItem("Joint","Joint")}; String accountCategory; AccountHolderDetailVO accountHolder1 = new AccountHolderDetailVO(); AccountHolderDetailVO accountHolder2 = new AccountHolderDetailVO(); // setter and getters } 

AccountHolderDetailVO

 public class AccountHolderDetailVO { String personName; String personAge; Date personDOB; String personAddress; // getter and setter } 

The default radio button is "Single". The secondAccountHolderId panel is displayed when the user clicks the Share button.

When you enter any values โ€‹โ€‹in the panel "firstAccountHolderId" or "secondAccountHolderId" and changing the switch, the entered values โ€‹โ€‹are lost.

+4
source share
1 answer

Here

 <p:ajax process="@this" event="change" update="@form" partialSubmit="true" /> 

you basically say that JSF only passes (processes) the current field (and therefore not all other fields of the form!), and then re-processes (updates) the entire form (and thus includes all other fields that were not shipped / processed!).

So, all other fields simply redraw the initial values โ€‹โ€‹from the bean instead of the values โ€‹โ€‹that were entered but not sent.

You need to change update="@form" accordingly so that it only updates the components that really need to be updated, depending on the change in the switch. For instance.

 <p:ajax process="@this" event="change" update="secondAccountHolder" partialSubmit="true" /> ... <h:panelGroup id="secondAccountHolder"> <h:panelGrid id="secondAccountHolderId" columns="2" styleClass="float-left" rendered="#{captureAccountDetailBackingBean.accountCategory eq 'Joint'}"> ... </h:panelGrid> </h:panelGroup> 

See also:

+12
source

All Articles