问题
I'm using Myfaces 2.2 with Client-side state saving. I see that the ViewScoped beans & data stored in viewmap is lost after the user session is destroyed. I came to know, not sure if it is correct, that this is the expected behavior but then what's the way to avoid view expired exceptions after session destroy?
My problem is that I destroy the user session pretty quickly after some inactivity period(like after 20 minutes) but I want the viewscope data to survive even after that(when using client saving) so that when the user comes back after session destroy, he doesn't need to do a page refresh. I dont know why & how this is so implemented but It is very normal that the user may be busy reading some section of website or be away for 20 minutes, & as he comes back & interacts with opened pages, how would I make that work without the state ? I think this is a common requirement for any public websites.
I think the internally used jsf viewstate is not lost, if I use client side state saving(as my pages still work), but then why are those viewscoped beans scoped that were also serialized to page along with the viewstate.
If this the designed behavior, Is there any way I could make the view scoped data survive session expiration ?
回答1:
An answer that I got from the myfaces users mailing list:
viewRoot.getAttributes()
map could be used to persist the viewscoped values even after session destroys. Thus instead of storing values to viewRoot.getViewMap()
, store in the map returned by viewRoot.getAttributes()
. However care should to be taken to ensure that the stored values are serializable.
来源:https://stackoverflow.com/questions/21643250/how-to-survive-viewscoped-beans-viewmap-after-session-destroy-using-client-side