3 Replies Latest reply: Sep 28, 2008 2:20 AM by PaKo RSS

    Managed bean action listener method get called twice.

    638522
      I'm using a commandMenuItem in a JSF fragments called by a taskflow.

      <af:commandMenuItem id="idCmd" text="foo" actionListener="#{pageFlowScope.myBean.foo}"/>

      I have a managedBean with the foo method declared at the pageFlow scope inside the taskFlow definition.

      public void foo(ActionEvent event)
      {
      ...
      }

      The commandMenuItem is inside a table component, which iterates through records.
      Inside the method, I evaluate an EL expression to get the current row, and perform modifications on that row.

      Everything is working fine, but the problem is the method is getting called twice, and the second time, the EL expression will evaluate to null and crash my application.
      Anyone knows why the method on the managed bean gets called twice ?

      Checking the process with Firebug confirmed me there is only one request send to the server during that action.

      Thanks
        • 1. Re: Managed bean action listener method get called twice.
          Frank Nimphius-Oracle
          Hi,

          this seems to be a matter of the JSF lifecycle that causes this. Most developers handle this in setting a flag that recognizes if a method has been executed before to suppress the second call

          Frank
          • 2. Re: Managed bean action listener method get called twice.
            638522
            Frank Nimphius wrote:
            Hi,

            this seems to be a matter of the JSF lifecycle that causes this. Most developers handle this in setting a flag that recognizes if a method has been executed before to suppress the second call

            Frank
            Hi Frank,

            What do you mean by "a matter of the JSF lifecycle" ?

            If I look at the Figure 20-2 of the BC Guide, it says the invokeApplication JSF Lifecycle phase will call the invokeApplication on the ADF PageLifecyclePhase...
            Does the duplication come from there ?
            If not, what is the exact origin then ?

            Thanks!
            • 3. Re: Managed bean action listener method get called twice.
              PaKo
              Hi!

              There are several similar misbehaviors, as far as I learned:

              1. The af:table is automatically making the postback on initial page load. Thus if you have some sort of cascade PPR (from table to something else inside table or around table) it may produce some error and the lifecycle is executed twice! I had similar problems with subforms and some other naming container elements which wrongly decoded the partial trigger references etc.

              2. The ADFm is exhibiting strange behavior when you have methodIterators and your method is returning null instead of empty list. Then the iterator is invoking the method twice (this is bug for me, but I can understand that devs could consider it "by design").

              I have not seen exactly the same problem you have. But from my experience try finding some errors that are happening in the background. Sorry for suggesting such and trivial issue, but do you have both actionListener and action of the button binded to same listener?

              Regarding the JSF/ADF LifeCycle, the specs specify that the getters/setters may be invoked multiple times during the lifecycle but the listeners are invoked only once. Otherwise it would be impossible from backing bean to determine the phase thus to provide any logic.


              Regards,

              PaKo