4 Replies Latest reply on Dec 19, 2009 10:05 AM by cwagnor

    Conditional rerender post a4j:command link action

      Hi All

       

      I was going through all the online documentation and couldn't find solution to my problem.

      Is it possible to render or process different things depending on the output of a4j:commandButton or link?

       

      My scenario:

      I have a datalist where I display a few records. With each record I have "Delete" option. This link should delete the record in the database and refresh the current datalist. Currently my action associated with Delete link is returning void. However I want to explore options of where I can return a string value for failure/success and depending on the return value, I can either show modal window (for failure) OR reRender the datalist (for success).

       

      Any help will be appreciated to achieve this.

       

      Thanks

      ~Chris

        • 1. Re: Conditional rerender post a4j:command link action

          you can do this via a a4j:commandButton/a4j:command link .

           

          on action goto the bean and there process the logic for delete . If the process is sucessful / failure you update a variable which is bindinded with UI  h:inputText which is hidden [you have to give this in  reRender attribute of a4j:commandButton/a4j:command link ]. now oncomplete of a4j:commandButton/a4j:command link   you check for that hidden h:inputText value . if it is sucess then show a modal window with ok button for sucessful deletion, and click of the "ok" rerender the grid and close the modal window. Else if its faliure show another modal window with failure message , here on click of ok, don't rerender the grid.

          1 of 1 people found this helpful
          • 2. Re: Conditional rerender post a4j:command link action
            Note:if you don't want to show sucessful message, then check by javascript  if that hidden  h:inputText value is sucess , then instade of showing sucessful message panel , just click a another hidden a4j:commadButton there specify the grid id in reRender attribute.
            1 of 1 people found this helpful
            • 3. Re: Conditional rerender post a4j:command link action
              nbelaevski

              Hi Chris,

               

              You can bind reRender to your bean:

              reRender="#{yourBean.someProp}"
              

              And set this property in your action/actionListener code.

              • 4. Re: Conditional rerender post a4j:command link action

                Thanks Deb and Nick

                 

                Nick's solution seems very easy, I'll try this for sure. Actually never thought of doing it this way, this will solve some of my hacks on the UI.

                 

                Thanks again

                ~Chris