开发者

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. So what's t开发者_Python百科he 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. 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. 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 (i.e. you return void or null in bean action method). When you navigate away to another view, e.g. 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.

See also:

  • Benefits and pitfalls of @ViewScoped
  • Any disadvantages of JSF 2.0?


Ripped straight from Core JavaServer Faces, 3rd Edition:

View Scope

View scope was added in JSF 2.0. A bean in view scope persists while the same JSF page is redisplayed. (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.
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. This is particularly useful for Ajax applications.


Maybe you are looking for the 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. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜