簡単なユースケースの説明:
ユーザーが次のページにアクセスしますhttp://localhost:8080/.../show.xhtml?itemId=1
。私ShowBean
は@RequestScopedJSFマネージドBeanであり、IDを取得<f:viewParam.../>
し、データベース内のアイテムを検索します。
<f:metadata>
<f:viewParam name="itemId" value="#{showBean.itemId}">
<f:convertNumber integerOnly="#{true}"/>
</f:viewParam>
</f:metadata>
<f:event type="preRenderView" listener="#{showBean.init()}"/>
ユーザーは表示されたアイテムを編集することもできます。ItemEditBean
@ViewScopedをオンデマンドで作成したい([編集]ボタンをクリックして)。これを達成するために、私は次のことを行いました。
<p:commandButton value="Edit" oncomplete="editWidget.show()" update=":itemEditForm">
<f:setPropertyActionListener target="#{itemEditBean.id}" value="#{showBean.itemId}"/>
</p:commandButton>
私の質問は次のとおりです。itemIdを@ViewScopedBeanに渡すためのより良いアプローチはありますか?
編集:
itemEditBean.fetch(id)
ボタンのアクションを実行しても、p:command
ページレンダリングで@ViewScopedBeanは初期化されません。
<p:commandButton value="Edit" oncomplete="editWidget.show()" update=":itemEditForm" action="#{itemEditBean.fetchItem(showBean.itemId)}"/>
。
上記のコードを使用すると、itemEditBeanはオンデマンドで構築されます。