af:setActionListenerおよびprocessScopeについて

af:setActionListenerタグには、ナビゲーションの前にアクション・ソース(commandButtoncommandLinkなど)に値を設定させる宣言方式が用意されています。af:setActionListenerの最も便利な使用例には、ADF FacesのELスコープprocessScopeを使用して、Javaコードを記述せずにページ間で値を受渡しする場合があります。

マスター・ページで従業員を示す単一選択用の表があると仮定します。コマンド・ボタンのaction属性は、静的な文字列結果showEmpDetailに設定されています。

<af:table value="#{myManagedBean.allEmployees}" var="emp">
  <f:facet name="selection">
    <af:tableSelectOne text="Select and press...">
      <af:commandButton text="Show more details" action="showEmpDetail">
        <af:setActionListener from="#{emp}" 
                              to="#{processScope.empDetail}" />
      </af:commandButton>
    </af:tableSelectOne>
  </f:facet> 
  <af:column>
    <f:facet name="header">
      <af:outputText value="Name"/>
    </f:facet>
    <af:outputText value="#{emp.name}"/>
  </af:column>
  <af:column>
    <f:facet name="header">
      <af:outputText value="Department Number"/>
    </f:facet>
    <af:outputText value="#{emp.deptno}"/>
  </af:column>
</af:table>     

af:setActionListenerタグにはfromtoの2つの属性があります。このタグはfrom値を取得し、その値をto値に格納します。

現行の従業員(または表の現在行)はEL変数{#emp}で取得されます。この行オブジェクトは、processScopeempDetailプロパティとしてEL式#{processScope.empDetail}に格納されます。バッキングBeanにJavaコードを記述する必要はありません。コマンド・ボタンのaction属性は、静的な文字列結果showEmpDetailです。

ユーザーが従業員の行を選択してコマンド・ボタンを押すと、アクション・リスナーは現行の従業員をリスニングして取得し、processScopeに格納します。次に、静的な結果を使用してアクション・イベントが機能し、現行の従業員に関する詳細データを示す詳細ページが表示されます。この詳細ページでは、次のコード・スニペットで示すように、processScope.empDetailオブジェクトを参照します。

...
<h:panelGrid columns="2">
  <af:outputText value="Firstname:"/>
  <af:inputText value="#{processScope.empDetail.name}"/>
  <af:outputText value="Email:"/>
  <af:inputText value="#{processScope.empDetail.email}"/>
  <af:outputText value="Hiredate:"/>
  <af:inputText value="#{processScope.empDetail.hiredate}"/>
  <af:outputText value="Salary:"/>
  <af:inputText value="#{processScope.empDetail.salary}"/>
</h:panelGrid> 
...    

af:setActionListenerおよびaf:resetActionListenerについて
ADF FacesのprocessScopeについて
ADF Facesでのダイアログに対する値の受渡しについて