3 Replies Latest reply on Feb 28, 2012 9:46 AM by howhigh

    a4j:commandButton and page refresh problem

    howhigh

      Hi,

       

      I have a page which has a part that can change when an user click on a a4j:commandButton.

      <div>
                  <a4j:outputPanel id="panelItems" layout="block">
                      <rich:panel rendered="#{fhIndBean.displayPanelItems}">
                          <h:form>
                              <rich:tabPanel switchType="ajax"
                                  activeItem="#{fhIndBean.activeTab}">
                                ...
                              </rich:tabPanel>
                          </h:form>
      
                          <h:form>
                              <a4j:commandButton styleClass="no-decor" value="#{msg.addMessage}"
                                  render="panelListCh, panelItems"
                                  actionListener="#{fhIndBean.displayListInvoiceLines}">
                              </a4j:commandButton>
                          </h:form>
                      </rich:panel>
                  </a4j:outputPanel>
      
                  <a4j:outputPanel id="panelListCh" layout="block">
                      <rich:panel rendered="#{fhIndBean.displayPanelListCh}">
                          <ui:include src="./fhIndDetails/listInvoiceLines.xhtml" />
                          <h:form>
                              <a4j:commandButton styleClass="no-decor" value="#{msg.cancel}"
                                  render="panelItems, panelListCh"
                                  actionListener="#{fhIndBean.cancelDisplayListInvoiceLines}">
                              </a4j:commandButton>
                          </h:form>
                      </rich:panel>
                  </a4j:outputPanel>
              </div>
      

       

      In my bean, I've two booleans which indicate wheter or not a part should be rendered and two listeners:

       

      private boolean displayPanelItems = true;
      private boolean displayPanelListCh = false;
      ...
      public void displayListInvoiceLines() {
              LOGGER.error("DISPLAY");
              displayPanelItems = false;
              displayPanelListCh = true;
                ...
          }
      
          public void cancelDisplayListInvoiceLines() {
              LOGGER.error("CANCEL");
              displayPanelItems = true;
              displayPanelListCh = false;
                ...
          }
      

       

      By default, panelItems is rendered.

      When I click on the commandButton in this panel, it's hidden and the panel panelListCh is rendered. Till now everything works as expected:

       

      16:24:56.279 [http-bio-8280-exec-5] ERROR LifeCycleListener - START PHASE RESTORE_VIEW 1
      16:24:56.375 [http-bio-8280-exec-5] ERROR LifeCycleListener - END PHASE RESTORE_VIEW 1
      16:24:56.375 [http-bio-8280-exec-5] ERROR LifeCycleListener - START PHASE APPLY_REQUEST_VALUES 2
      16:24:56.379 [http-bio-8280-exec-5] ERROR LifeCycleListener - END PHASE APPLY_REQUEST_VALUES 2
      16:24:56.379 [http-bio-8280-exec-5] ERROR LifeCycleListener - START PHASE PROCESS_VALIDATIONS 3
      16:24:56.381 [http-bio-8280-exec-5] ERROR LifeCycleListener - END PHASE PROCESS_VALIDATIONS 3
      16:24:56.381 [http-bio-8280-exec-5] ERROR LifeCycleListener - START PHASE UPDATE_MODEL_VALUES 4
      16:24:56.383 [http-bio-8280-exec-5] ERROR LifeCycleListener - END PHASE UPDATE_MODEL_VALUES 4
      16:24:56.383 [http-bio-8280-exec-5] ERROR LifeCycleListener - START PHASE INVOKE_APPLICATION 5
      16:24:56.383 [http-bio-8280-exec-5] ERROR FhIndBean - DISPLAY
      16:24:56.383 [http-bio-8280-exec-5] ERROR LifeCycleListener - END PHASE INVOKE_APPLICATION 5
      16:24:56.384 [http-bio-8280-exec-5] ERROR LifeCycleListener - START PHASE RENDER_RESPONSE 6
      ...
      

      and panelListCh is well rendered.

       

      And now if I click on the commandbutton to display panelItems again I got some serious troubles:

      16:26:51.660 [http-bio-8280-exec-3] ERROR LifeCycleListener - START PHASE RESTORE_VIEW 1
      16:26:51.663 [http-bio-8280-exec-3] ERROR LifeCycleListener - END PHASE RESTORE_VIEW 1
      16:26:51.663 [http-bio-8280-exec-3] ERROR LifeCycleListener - START PHASE RENDER_RESPONSE 6
      16:26:51.732 [http-bio-8280-exec-3] ERROR FhIndBean - POSTCONSTRUCT
      ...
      

      The bean is rebuilt and the actionListener which normally should log the word CANCEL is not called.

      The fhIndBean is in ViewScope so normally, the problem with conditional rendering should not appeared (https://community.jboss.org/wiki/CommonAjaxRequestsProblems#conditionalRendering).

       

      If I put fhIndBean in SessionScope the problem is that it doesn't render the good panel because the actionListener isnt called (so booleans aren't changed) but the bean isnt rebuilt.

       

      If I change a4j:commandButton to h:commandButton everything is good except the fact that the page is refreshed (no ajax).

       

      What am I doing wrong?

       

      Thanks in advance!

        • 1. Re: a4j:commandButton and page refresh problem
          pvito

          Hi, howhigh

           

          If You use property "actionListener", You must define methods with event parameters.

           

           

          public void displayListInvoiceLines(javax.faces.event.ActionEvent event) {
                  LOGGER.error("DISPLAY");
                  displayPanelItems = false;
                  displayPanelListCh = true;
                    ...
              }

              public void cancelDisplayListInvoiceLines(
          javax.faces.event.ActionEvent event) {
                  LOGGER.error("CANCEL");
                  displayPanelItems = true;
                  displayPanelListCh = false;
                    ...
              }

           

          Regards, Vitaliy

          • 2. Re: a4j:commandButton and page refresh problem
            howhigh

            Hi Vitaliy,

             

            it's not mandatory. I try it but it's the same result.

            Look at the second logs, it jumps from phase 1 to 6 without going in phase 5 in which events are handled. It means that the bean is not found and it recreates it... but the bean is already present.

             

            Thanks anyway

            • 3. Re: a4j:commandButton and page refresh problem
              howhigh

              Nobody?