简体   繁体   English

视图范围bean是否在Navigation JSF中存活

[英]Does view scope bean survive Navigation JSF

I am quite confused with the view scope. 我对视图范围很困惑。 I thought it could survive a JSF navigation to another page (no redirect, obviously), but it doesn't. 我认为它可以在JSF导航到另一个页面(显然没有重定向),但它没有。 So what's the advantage to use it instead of request scope, that if i summoned the same view it will be the same object? 那么使用它而不是请求范围有什么好处,如果我召唤相同的视图它将是同一个对象?

The advantage is that the bean survives postbacks to the same view. 优点是bean可以将回发存活到相同的视图中。 You don't need to preserve any data yourself anymore when used in rendered attributes or as model for h:dataTable or as hidden inputs, etcetera. rendered属性中使用时,或者作为h:dataTable模型或隐藏输入等,您不需要自己保留任何数据。 In the past, a lot of hacks were been used to go around this. 在过去,很多黑客被用来解决这个问题。

A view scoped bean lives as long as you interact with the same view (ie you return void or null in bean action method). 只要您与同一视图交互(即在bean操作方法中返回voidnull ,视图范围的bean就会存在。 When you navigate away to another view, eg by clicking a link or by returning a different action outcome, then the view scoped bean will be trashed by end of render response and not be available in the next request. 当您导航到另一个视图时,例如通过单击链接或返回不同的操作结果,视图范围bean将在渲染响应结束时被删除,并且在下一个请求中不可用。

See also: 也可以看看:

Ripped straight from Core JavaServer Faces, 3rd Edition : 直接从Core JavaServer Faces,第3版中删除:

View Scope 查看范围

View scope was added in JSF 2.0. JSF 2.0中添加了视图范围。 A bean in view scope persists while the same JSF page is redisplayed. 视图范围中的bean在重新显示相同的JSF页面时仍然存在。 (The JSF specification uses the term view for a JSF page.) As soon as the user navigates to a different page, the bean goes out of scope. (JSF规范对JSF页面使用术语视图。)一旦用户导航到不同的页面,bean就会超出范围。
If you have a page that keeps getting redisplayed, then you can put the beans that hold the data for this page into view scope, thereby reducing the size of the session scope. 如果您有一个不断重新显示的页面,那么您可以将包含此页面数据的bean放入视图范围,从而减小会话范围的大小。 This is particularly useful for Ajax applications. 这对Ajax应用程序特别有用。

Maybe you are looking for the FlowScoped bean: 也许您正在寻找FlowScoped bean:

Faces Flows 面对流动

The Faces Flows feature of JavaServer Faces technology allows you to create a set of pages with a scope, FlowScoped , that is greater than request scope but less than session scope. JavaServer Faces技术的Faces Flows功能允许您创建一组具有范围FlowScoped的页面,该范围大于请求范围但小于会话范围。 For example, you might want to create a series of pages for the checkout process in an online store. 例如,您可能希望为在线商店中的结帐流程创建一系列页面。 You could create a set of self-contained pages that could be transferred from one store to another as needed. 您可以根据需要创建一组可以从一个商店转移到另一个商店的自包含页面。

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

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