1

I understand that t:saveState allows a request scope bean to persist for longer than request scope allows but shorter than session scope bean. You are also able to use t:saveState on an entire bean.

so my question is if you use t:saveState on an entire bean what are the advantage of using t:saveState over having the Bean configured in session Scope?

Also under what conditions do you make the bean request scope and use T:saveState instead of making the bean Session Scope to being with?

Thanks

ke3pup
  • 1,835
  • 4
  • 36
  • 66

1 Answers1

2

The bean which is referenced by <t:saveState> will live as long as the view lives. It does basically the same as the new JSF 2.0 view scope does.

This is particularly useful when you're dealing with data which should live as long as you're interacting with the same view by returning null or void on action methods. If you would have used the session scope, then multiple views (multiple browser windows/tabs within the same session) would all share the same data. This may have undesireable side effects when the enduser interacts with the page in multiple browser tabs/windows and switches between them. All changes done in one tab would be reflected in the other tab.

The session scope should absolutely only be used for real session scoped data, such as the logged-in user, its preferences, language, etcetera which can safely be shared between multiple browser windows/tabs within the same session.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • thanks BalusC. As always clear and concise answer. I also tried to leave feedback on your blog on the `Effective datatable paging and sorting` article but couldn't get passed the captcha code verification (tried more than 20 different capcha codes!) the article was an absolute lifesaver for me in getting pagination working in my application with SQL Server as database. So thank you x2 (please consider putting a paypal button on your blog. i feel like a leecher having used your code without even a thank you). – ke3pup Feb 19 '12 at 11:21