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?
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.