4 Replies Latest reply on Sep 18, 2008 12:48 PM by Anne Childress

    should rerender happen when errors exist?

    Anne Childress Newbie

      I have a problem where an a4j:commandButton is used to call an actionListener method which does some database updates. The a4j:commandButton tag has a reRender defined. I would like the reRender not to occur if the database updates fail for some reason. When there is such an error, I am adding an error message to the FacesContext, and assumed that this would be sufficient to stop the reRender from happening. Are these incorrect assumptions?

      Example code:

      <a4j:commandButton status="majorstatus" styleClass="stdLabel" value="Add Case" actionListener="#{DCCCaseBean.chooseAOCDOCOffender}" reRender="maincontent" rendered="#{IntakeAOCDOCSearchOffendersBean.DOCOffenderSelected}"/>
      
      


      If something goes wrong in chooseAOCDOCOffender, I do the following:
       FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), e.getMessage()));
      
      


      Should I expect maincontent to not be reRendered? If not, is there a way to prevent it from being reRendered so that I can display the error message using the rich:messages tag?

      HELP!

        • 1. Re: should rerender happen when errors exist?
          Ilya Shaikovsky Master

          You could bind reRender to some bean property List and fill this list in actionListener. If validation fails - this code will not beexecuted and reRender will eb empty. ;)

          • 2. Re: should rerender happen when errors exist?
            Anne Childress Newbie

            I've tried that, but the reRender of the id that was originally in the backing bean property referenced by the reRender attribute of the tag is still being reRendered. It is as if the reRender of the existing page ids is happening before the change of the backing bean property is obtained. For instance, if I code the commandButton this way:

            <a4j:commandButton status="majorstatus" id="saveButton" value="Search" actionListener="#{DCCCaseBean.doAOCDOCSearch}" oncomplete="checkerrors();" reRender="#{IntakeMenuBean.reRender}">
            


            IntakeMenuBean.reRender is a String attribute with the value of "maincontent". Then in the DCCCaseBean.doAOCDOCSearch actionListener method, I change IntakeMenuBean.reRender to an empty String, or even some other value as follows:

             FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_ERROR, "hey", "hey"));
             IntakeMenuBean anIntakeMenuBean = (IntakeMenuBean)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("IntakeMenuBean");
             anIntakeMenuBean.setReRender("searcherrors");
            


            maincontent is still being reRendered instead of searcherrors when the page is repainted. I don't understand why this is happening.

            • 3. Re: should rerender happen when errors exist?
              Ilya Shaikovsky Master

              because the bean with this property should be request scoped ;)

              • 4. Re: should rerender happen when errors exist?
                Anne Childress Newbie

                why would scope make any difference?