【发布时间】:2012-09-06 08:19:31
【问题描述】:
简要用例描述:
用户到达页面:http://localhost:8080/.../show.xhtml?itemId=1。
我的ShowBean 是一个@RequestScoped JSF Managed Bean,它通过<f:viewParam.../> 获取id 并在数据库中查找项目:
<f:metadata>
<f:viewParam name="itemId" value="#{showBean.itemId}">
<f:convertNumber integerOnly="#{true}"/>
</f:viewParam>
</f:metadata>
<f:event type="preRenderView" listener="#{showBean.init()}"/>
用户还可以编辑显示的项目。我想按需构建@ViewScoped ItemEditBean(通过单击“编辑”按钮)。为此,我做了以下工作:
<p:commandButton value="Edit" oncomplete="editWidget.show()" update=":itemEditForm">
<f:setPropertyActionListener target="#{itemEditBean.id}" value="#{showBean.itemId}"/>
</p:commandButton>
我的问题是:有没有更好的方法将 itemId 传递给 @ViewScoped bean?
编辑:
在p:command 按钮的操作中执行itemEditBean.fetch(id) 不会在页面呈现时初始化@ViewScoped bean。
<p:commandButton value="Edit" oncomplete="editWidget.show()" update=":itemEditForm" action="#{itemEditBean.fetchItem(showBean.itemId)}"/>.
通过上面的代码,itemEditBean 可以按需构建。
【问题讨论】: