Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF 2.0 - ViewScope and SessionScope advantages?

Tags:

jsf

It would be great if someone can help me understand, what's the advantage of ViewScoped bean when we have SessionBean injected into it.

Can we still save on session memory usage?

If we use only SessionScoped bean or ViewScoped bean with injected SessionBean, I believe there is no difference in session memory footprint.

Why do we go through so much hassles of using View and Session scoped beans when everything is achieved so smoothly with SessionScoped beans.

Thanks, Sundeep

like image 547
Sundeep Kadakia Avatar asked Dec 10 '22 04:12

Sundeep Kadakia


1 Answers

It's a very common situation when you need to keep the data just for one page and then destroy it when you navigate to another page. That makes @ViewScoped bean a reasonable choice. @SessionScoped managed bean will keep all the data in session. So, why pollute your session map, when the data is no longer needed?

Also note, that the @ViewScoped annotation is not available in CDI. So if you're using beans with @Named annotation (rather than @ManagedBean), then you're out of luck. However, there are some alternatives.

like image 125
jFrenetic Avatar answered Dec 28 '22 23:12

jFrenetic