af:setActionListener
タグには、ナビゲーションの前にアクション・ソース(commandButton
、commandLink
など)に値を設定させる宣言方式が用意されています。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
タグにはfrom
とto
の2つの属性があります。このタグはfrom
値を取得し、その値をto
値に格納します。
現行の従業員(または表の現在行)はEL変数{#emp}
で取得されます。この行オブジェクトは、processScope
のempDetail
プロパティとして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でのダイアログに対する値の受渡しについて
Copyright © 1997, 2007, Oracle. All rights reserved.