3 Replies Latest reply on Mar 7, 2007 3:57 PM by Sergey Smirnov

    EL usage in attributes reRender and oncomplete

    Michael Heinen Newbie

      Hi,

      I copied this topic from the dead mailing list.

      I use EL in the reRender and oncomplete attributes of a commandButton in order to decide on serverside what has to be updated. I read in the FAQ that the rerender attribute is evaluated before phase RENDER_RESPONSE.
      Therefore I put in my action a flag into the request scope specifying what has to be rerendered and rerendering is working fine so far.

      Sample:
      reRender="zoneA,zoneB,#{MyController.wasChanged? 'zoneC ':'zoneD'}"
      oncomplete="doA();doB();,#{MyController.wasChanged? doC(); ':'doD()'}

      public boolean getWasChanged()
      {
      return super.getRequestMap().containsKey(?changed?);
      }

      The problem is now that the wrong JS method is executed.
      When MyController.wasChanged is true then zoneC is rerendered and doD is called.
      In the following request MyController.wasChanged is false and zoneD is rerendered and doC is called.

      In which phase is the oncomplete attribute evaluated and why does it differ from reRender attribute?
      I think it is a common use case to rerender an area and call an area specific JS method (e.g to positionize elements).

      Any help is appreciated
      Michael

        • 1. Re: EL usage in attributes reRender and oncomplete
          Sergey Smirnov Master

          Yes, I see where is the problem here.

          the EL in the reRender might be changed until the 6th phase during the Ajax Request. It makes it possible to decide what to re-render even in the action method on the 5th phase.

          oncomplete is another story. It is pure client side behavior, so, i guess, the value is formed already before the Ajax Request

          What I can suggest to do is using the static javascript function name in the oncomplete, but put this function inside the re-render area. So, you will be able to change the body on the function on the server side.

          Important tip: do not use the local variable there if you expect they should be available from outside directly. When browser replaces the script the local-global issue takes place.
          Example of local:
          var foo=bar;
          Example of global:
          window.foo = bar;

          • 2. Re: EL usage in attributes reRender and oncomplete
            Michael Heinen Newbie

            Thanks Sergey.
            I try it with a static JS function, rerender it and call inside the right JS method. This should work of course. I avoided it to define any JS inside a page so far.

            Would it not be better to evaluate both attributes in the same phase? What's the benefit of doing it like it is currently?

            Thanks for your help,
            Michael

            • 3. Re: EL usage in attributes reRender and oncomplete
              Sergey Smirnov Master

              what is inside the oncomplete might not be evaluated on the same phase because it works on the client side not on the server side. So, we have to return the content of the oncomplete with ajax response and than evaluate.