Handling obsolete ViewState in JSF and Richfaces

I have a number of registration pages that are built on top of each other. When the user session ends, I have a Listener that clears everything on the server, and this works fine. But, if the user is trying to do something else, I just want to redirect them to the first page of the series. However, my filter does not work correctly. I keep getting javax.faces.application.ViewExpiredException

What is the best practice for handling this experience? I cannot just process in web.xml because it is too global. In addition, the error page is derived from some JSF code - it seems I need to catch that this happens using PhaseListener, so the exception does not occur in the first place, but I could not find a good model how to do this. Any ideas?

+6
java jsf viewexpiredexception richfaces
source share
5 answers

Richfaces has its own ViewExpiredException engine, see Richfaces docs .

+2
source share

I think you're the right track with a phase listener. Essentially something in the session on the first page. Then, in phase listening, find the value in the session. If it does not exit, redirect. The trick is to do this at the beginning of the phase listener process. Not sure exactly where in the process your phase listener throws an exception.

+1
source share

The way I handle this is to add a filter to web.xml only mapped to the URLs you want to track. This filter checks to see if the session has ended and is then redirected to the login page, if so. It should work if the filter runs before any JSF code is run.

+1
source share

In the past, I used a handler that validates a field in a managed bean session. If the user session is interrupted, the listener clears the mbean and puts the user as not logged in. Each request is sent through a listener, and if the requirements are not met, the user is forced out of the site. I never get a ViewExpiredException in my log. The only time this exception occurred is if the server was restarted and the user requests a page from a previous active session.

+1
source share

You can check if your session is invalid or not.

boolean sessionInValid = httpServletRequest.getRequestedSessionId ()! = null && &! HttpServletRequest.isRequestedSessionIdValid ();

Here, the boolean variable sessionInValid will return true if the session is invalid by any means.

You can add this to a filter or listener, and then configure this in your web.xml file.

0
source share

All Articles