Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"Correct" way to detect timeout in form handling?

 
David Balažic
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

In a JSF/Tomcat project, we have a chain of form pages.
The first page sets a few properties of a session scoped managed bean and then calls on submit a method of that same bean.
Then the next page with form is loaded, which sets some other properties of the same bean and on submit calls a different method of that same bean.

If the session times out before this second submit, then the bean method will have the properties from the first page uninitialized.
This condition should be detected and handled by redirecting to another page.

The question is, how to do it?

I googled and found some different approaches:
- in bean code, test the request.getSession(false) value
- in bean code, misuse one property as an indicator if the prevoius forms were submitted
- declare a filter that checks the session before the servlet code is called
- declare a JSF phase listener, that checks for timeout and redirects

Is there a "one true" way? An official recommendation? Good practice?

Regards,
David

Material I found on web:
http://www.coderanch.com/t/213277/JSF/java/Session-time-out-JSF
http://jsweetland.livejournal.com/3229.html (faces phase listener)
http://techieexchange.blogspot.com/2008/02/jsf-session-expiry-timeout-solution.html (filter)
 
Christian Nicoll
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,

my first intention was to get the session over the request and then to check with the isNew() if a new session was created or if an "old" valid session was received. I assume that the way with request.getSession(false) is more performant, and so I would use this way.

I don't know if there exists an offical recommendation.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you referring to the infamous and much-hated ViewExpiredException?

I'm still working on that one myself, actually. JSF version 2 is supposed to add some features that will help, but apparently they're yet to actually address the problem directly.
 
David Balažic
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:Are you referring to the infamous and much-hated ViewExpiredException?

I don't think so ;-)
I didn't see that Exception (yet).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic