Invoking method action automatically in ADF

Sometimes you need that a methodAction runs automatically when you load a page in ADF. This is very common when you have a form on a page and the result is shown on another page.

Download the sample application – InvokeMethodActionAutoApp.zip – it has a task flow with two pages, List and Result. The List page has two buttons, and when I click on them, the Result page is shown. Before the Result page is loaded, a methodAction is invoked.

This is the task flow:

invoking-method-action-automatically-in-adf1

The List page has the following code:

<af:document id="d1" title="CurrencyConverter">
  <af:form id="f1">
    <af:panelGroupLayout id="pgl1" layout="vertical">
      <af:outputText value="Currency Converter:" id="ot1"/>
      <af:spacer width="10" height="10" id="s2"/>
      <af:commandButton text="Brazilian Real (BRL) to U.S. Dolar (USD)" id="cl1" action="goResult">
        <af:setActionListener from="#{'BRL'}" to="#{pageFlowScope.fromCurrency}"/>
        <af:setActionListener from="#{'USD'}" to="#{pageFlowScope.toCurrency}"/>
      </af:commandButton>
      <af:spacer width="10" height="10" id="s1"/>
      <af:commandButton text="Brazilian Real (BRL) to Euro (EUR)" id="cl2" action="goResult">
        <af:setActionListener from="#{'BRL'}" to="#{pageFlowScope.fromCurrency}"/>
        <af:setActionListener from="#{'EUR'}" to="#{pageFlowScope.toCurrency}"/>
      </af:commandButton>
    </af:panelGroupLayout>
  </af:form>
</af:document>

The Result page has the following code:

<af:document id="d1" title="CurrencyConverter">
  <af:form id="f1">
    <af:panelGroupLayout id="pgl1" layout="vertical">
      <af:panelGroupLayout id="pgl2">
        <af:outputText value="The conversion rate from #{pageFlowScope.fromCurrency} to #{pageFlowScope.toCurrency} is: "
                       id="ot2"/>
        <af:outputText value="#{bindings.Return.inputValue}" id="ot1">
          <af:convertNumber groupingUsed="false"
                            pattern="#{bindings.Return.format}"/>
        </af:outputText>
      </af:panelGroupLayout>
      <af:spacer width="10" height="20" id="s1"/>
      <af:commandButton text="Back" id="cb1" action="goList"/>
    </af:panelGroupLayout>
  </af:form>
</af:document>

This is the binding of Result page:

invoking-method-action-automatically-in-adf2

All you have to do is create an invokeAction inside Executables section, and move it to the first place, to execute initially before any other executable.

invoking-method-action-automatically-in-adf3

invoking-method-action-automatically-in-adf4

Change the Refresh property to Always.

invoking-method-action-automatically-in-adf5

This is the result!

invoking-method-action-automatically-in-adf6

invoking-method-action-automatically-in-adf7

Waslley Souza

Author: Waslley Souza

Consultor Oracle com foco em tecnologias Oracle Fusion Middleware e SOA. Certificado Oracle WebCenter Portal, Oracle ADF e Java.

Leave a Reply

Your email address will not be published. Required fields are marked *