0

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 ?

Rajat Gupta
  • 25,853
  • 63
  • 179
  • 294
  • View scope is a narrower scope than session scope. It shouldn't survive a session timeout, and if it did, it would cause a huge discrepancy depending on whether you have client or server state saving. – Kayaman Feb 08 '14 at 07:50
  • 1
    The viewscope is dependent on the session scope (the beans are stored within the context of the session), so destroying the session gets rid of the beans inside it too – kolossus Feb 08 '14 at 09:24
  • So then what's the way to avoid view expired exceptions after session is destroyed? I keep the user session on server only for 20 minutes 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 restore the view state for that ? This is a pretty normal scenario in any website. How do other JSF websites deal with this ? In short I want to be able to respond to user anytime he comes back & interacts with older pages, how could I design for that ? – Rajat Gupta Feb 10 '14 at 18:59
  • It isn't a real answer, but going stateless (maybe with viewscope for the intermittent ajax requests) solves your problem. Opens up a whole new can of worms, though. – mabi Feb 10 '14 at 20:26
  • hey, I found a solution to this (posted below as answer). Any your reviews on this solution? – Rajat Gupta Mar 29 '14 at 11:45

1 Answers1

0

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.

Rajat Gupta
  • 25,853
  • 63
  • 179
  • 294