I am looking for a JSF-based way to detect when a session is expiring and run some code before it dies. Specifically, I am writing a myfaces/tomahawk web application, and wish to save some user state information to the database when the session expires. When they next log in, they will have their previous state restored.

I have an ugly solution to this problem from my last Struts app, but I'm looking for something cleaner. In Struts, when someone logged in, I manually added a bean to the session with a specific attribute name (e.g. "USER"). Then I registered a HttpSessionAttributeListener, and in the attributeRemoved method I compared the name of the attribute being removed to the bean's name. If they matched, then the bean was being removed from the session, meaning this user was logging off.

It was normal in my Struts app to manually get and set request and session attributes, but using JSF has obviated the need for such mess and clutter... until now. So I would really like to keep things clean, and find a better, JSF-oriented way. Any ideas?

Are JSF managed-beans guaranteed to have a certain name, when their session attribute is removed? Maybe I could still do a comparison in the listener, despite never explicitly adding anything to the session directly...

Regards,

Jeff Bischoff
Kenneth L Kurz & Assoc, Inc.


Reply via email to