Benefits of JSF 2.0 - ViewScope and SessionScope?

It would be great if someone can help me understand the advantage of the ViewScoped bean when we introduced a SessionBean into it.

Can I save session memory storage?

If we use only a SessionScoped bean or ViewScoped bean with a SessionBean introduced, I believe that there is no difference in the memory area of ​​the session.

Why are we faced with so many problems using View and Session scoped beans when everything is achieved so seamlessly with SessionScoped beans.

Thanks Sundeep

+4
source share
2 answers

This is a very common situation when you need to store data for only one page, and then destroy it when going to another page. This makes @ViewScoped bean a smart choice. @SessionScoped bean will store all the data in the session. So, why pollute your session map when data is no longer needed?

Also note that the @ViewScoped annotation @ViewScoped not available in CDI. Therefore, if you use beans with the @Named annotation (and not @ManagedBean ), you're out of luck. However, there are several alternatives.

+6
source

When you place everything in your session, you are using more memory. A session usually ends after 35 minutes or by default.

Viewscoped beans are free to collect garbage after switching views.

For small objects this is probably not a big deal in small applications. However, if you, for example, store return values ​​from the database in your session, you will have to take care of the memory used.

+2
source

Source: https://habr.com/ru/post/1385423/


All Articles