invokeAction Invoked Twice

Symptom

Suppose you published an Application Module method as a client method, f.ex.:


public void yourMethod() {
   System.out.println("Hello World");
}

You created an ADF Faces page and included the following in your page definition (<yourPage>PageDef.xml):


...
  <executables>
    ...
    <invokeAction Binds="yourMethod" id="executeYourMethodAction"
                  RefreshCondition="${!adfFacesContext.postback}"/>
    ...
  </executables>
  <bindings>
...
  <methodAction id="yourMethod" InstanceName="AppModuleDataControl.dataProvider"
                DataControl="AppModuleDataControl" MethodName="yourMethod"
                RequiresUpdateModel="true" Action="999"
                IsViewObjectMethod="false"/>
  </bindings>
</pageDefinition>

The aim is to execute yourMethod when the page first renders (controlled by the RefreshCondition).
The method is correctly executed, but you see it's executed twice.
The Log window of JDeveloper shows:


Hello World
Hello World 

Cause

The property Refresh is not defined for the invokeAction.
Its default value is ifNeeded, what means that the related action binding will be invoked twice during each request.


Solution


You should change the default Refresh setting for the invokeAction bindings to either prepareModel or renderModel.
With prepareModel, your invokeAction will be invoked before the JSF invokeApplication phase.
With renderModel, your invokeAction will be invoked after the JSF invokeApplication phase.

Since JSF's invokeApplication phase is when the JSF action events fire, you should decide if you want your invokeAction to trigger before (prepareModel) or after (renderModel) the action listeners have performed their processing,

For more information, see the ADF Develoepr's Guide, topic "10.5.5.3 Correctly Configuring Refresh Property of InvokeAction Executables"


Comments:

First of all, why the invokeAction is called twice when the refresh property is set to ifNeeded?

Posted by Kavin on February 24, 2009 at 12:16 AM CET #

Hi Kavin, that's per our ADF Framework design. The ADF lifecycle doesn't know the purpose of your action. It doesn't know if it should be executed before or after the invokeApplication. Hence it executes it twice by default. However, we recommend to change this default, as explained in the ADF Developer's Guide. Regards, Didier

Posted by Didier on February 24, 2009 at 01:06 AM CET #

Post a Comment:
Comments are closed for this entry.
About

Didier Laurent - Sr Principal Support Engineer in the JDeveloper team

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today