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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With