1

我在我的应用程序中使用 PrimeFaces,其中我有一个填充了数据的数据表。我也有一个编辑命令按钮。

现在我想打开一个新的 JSF 页面。执行此操作的操作绑定到视图范围内的支持 bean。在操作方法中,我可以访问 bean 的值,但在新的 JSF 页面上,我无法再访问该 bean 的任何值。

这是我的代码:

<p:commandLink title="Edit" id="editBtn" action="#{personRegisterController.selectPerson}">
    <f:setPropertyActionListener value="#{person}" target="#{personRegisterController.personBean}"/>
</p:commandLink>
4

1 回答 1

4

The view scope in JSF is the scope that entails only a single view (page). So, as long as you post-back to the same view, you'll retain the data of view scoped beans.

However, as soon as you navigate to a new view a new view scope starts. In other words, you cannot use the view scope to transfer data between views (between requests to different pages).

See this answer for one possible solution on how you can do this transferring: p:commandButton doesn't execute f:setPropertyActionListener in JSF 2

Incidentally, note that the setPropertyActionListener isn't necessary for what you're doing here. You can provide the data directly to your action method:

<p:commandLink action="#{personRegisterController.selectPerson(person)}"/>
于 2012-08-19T15:03:30.763 回答