0

簡単なユースケースの説明:

ユーザーが次のページにアクセスします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はオンデマンドで構築されます。

4

2 に答える 2

0

問題は、パラメータを保持しない後続のリクエストでshowEditBean再構築されることです。INVOKE_APPLICATION

を使用してそれらを保存してf:paramください。

<p:commandButton value="Edit" oncomplete="editWidget.show()" update=":itemEditForm">
    <f:param name="itemId" value="#{showBean.itemId}"/>
    <f:setPropertyActionListener target="#{itemEditBean.id}" value="#{showBean.itemId}"/>
</p:commandButton>

@ViewScopedPS Bean のライフサイクルについては正しかっですaction

于 2012-09-06T08:47:38.340 に答える
0

@ViewScoped はプロではないと思います。部分的なフォーム送信を試してください。たとえば、このように、

 <p:commandLink immediate="true" id="addAccessoriesLink" update=":accessoriesEntryForm">  
        <h:graphicImage url="/images/add.png" styleClass="action-img"/>
              <f:setPropertyActionListener value="# AccessoriesActionBean.newAccessories}" target="#{AccessoriesActionBean.newAccessories}" />
  </p:commandLink>
于 2012-09-06T08:35:12.800 に答える