1 Reply Latest reply on Feb 10, 2012 2:50 PM by stamar

    a4j:ajax , revert datamodel changes

    stamar Newbie

      Hi all;

        I have a module in my application for user administration. When administrator changes the role of the person (in a popup window), other fields must be rendered .... see the piece of code below:


                                   <h:panelGroup layout="block" styleClass="sie-field">

                                      <h:panelGroup styleClass="popup-row">

                                          <cc:outputLabel forId="entry-role" colon="true" required="true" value="#{msgs.user_Role}" />



                                          <rich:select id="entry-role" value="#{administrationBean.person.role}" required="true">

                                              <a4j:ajax render="entry-substituteActive,entry-substitute,entry-substitute-label,entry-auditor,entry-auditor-label" execute="@this" event="selectitem" />

                                              <f:selectItems value="#{administrationBean.dataService.roles}" var="item" itemValue="#{item}" itemLabel="#{item.name}" />

                                              <rich:validator />


                                          <rich:message for="entry-role" />




      I have a problem, when administrator edits the person info....so e.g. edited person has set 'role1'. The administrator changes this role to 'role2' (a4j:ajax changes my data model) and he press cancel button. In the model stays value role2 ... and that is the problem.


      my cancel button looks as follows:

                                 <a4j:commandButton id="abort-popup" value="#{msgs.buttonAbort}" action="#{applicationBean.refreshView}" immediate="true" oncomplete="#{rich:component('person-popup')}.hide();" />


      refreshView method:

      public void refreshView() {

              FacesContext context = FacesContext.getCurrentInstance();

              Application application = context.getApplication();

              ViewHandler viewHandler = application.getViewHandler();

              UIViewRoot viewRoot = viewHandler.createView(context, context.getViewRoot().getViewId());





      This method refreshes everything except the values that were changed by a4j:ajax


      Has anyone idea, how to solve it?

      Thanks a lot


        • 1. Re: a4j:ajax , revert datamodel changes
          stamar Newbie

          I solved already the problem.


          - in the administrationBean I created private variable originalRole and the setter.

          - I also created method refreshView in this administrationBean (because the one from applicationBean was generally used on many places in my app) and added row


          at the end of the method

          - to the edit-commandLink (on the jsf page) I added setPropertyActionListener

          <f:setPropertyActionListener target="#{administrationBean.originalRole}" value="#{person.role}" />


          I hope it helps somebody