简体   繁体   English

JSF 2.0视图范围不起作用

[英]JSF 2.0 view scope not working

I use PrimeFaces in my application, in which I have a data table populated with data. 我在我的应用程序中使用PrimeFaces,其中我有一个填充了数据的数据表。 I also have one edit command button. 我还有一个编辑命令按钮。

Now I would like to open a new JSF page. 现在我想打开一个新的JSF页面。 The action to do that is bound to a backing bean in view scope. 执行此操作的操作绑定到视图范围中的辅助bean。 In the action method I have access to the bean's values, but on the new JSF page I can't access any values of this bean anymore. 在action方法中,我可以访问bean的值,但是在新的JSF页面上,我再也无法访问这个bean的任何值。

This is my code: 这是我的代码:

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

The view scope in JSF is the scope that entails only a single view (page). JSF中的视图范围是仅包含单个视图(页面)的范围。 So, as long as you post-back to the same view, you'll retain the data of view scoped beans. 因此,只要您回发到同一视图,您将保留视图范围bean的数据。

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 有关如何进行此转移的一个可能解决方案,请参阅此答案: p:commandButton在JSF 2中不执行f:setPropertyActionListener

Incidentally, note that the setPropertyActionListener isn't necessary for what you're doing here. 顺便提一下,请注意, setPropertyActionListener对于您在此处所做的事情不是必需的。 You can provide the data directly to your action method: 您可以直接向您的操作方法提供数据:

<p:commandLink action="#{personRegisterController.selectPerson(person)}"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM