Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling an expired ViewState in JSF and Richfaces

I have a series signup pages that build on each other. When the users session expires I have a Listener that cleans everything up on the server and that works great. But, if the user attempts to do anything else I just want to redirect them back to the first page of the series. However, my filter doesn't seem to work correctly. I keep getting javax.faces.application.ViewExpiredException

What is the best practice for handling this expcetion? I can't really just handle in web.xml because that's too global. Plus the Error page is being rendered from some JSF code - it seems like I need to catch that this is happening using a PhaseListener so the exception doesn't happen in the first place, but I haven't been able to find a good model for how to do this. Any ideas?

like image 366
Kyle Boon Avatar asked Aug 04 '09 18:08

Kyle Boon


3 Answers

Richfaces has their own mechanism for handling ViewExpiredException, look at Richfaces docs.

like image 123
MarrLiss Avatar answered Nov 03 '22 21:11

MarrLiss


I think you are the correct track with a phase listener. Essentially set something up in session on the first page. Then in phase listener look for the value in session. If it doesn't exit then do a redirect. The trick is to do it early in the phase listener process. Not sure exactly where in the process your phase listener is throwing the exception.

like image 20
JeffJak Avatar answered Nov 03 '22 20:11

JeffJak


The way I handle this is to add a filter to the web.xml only mapped to the urls you want to track. That filter checks if the session is expired, and then forwards to a login page if it is. It should work if the filter is run before any JSF code is run.

like image 1
Colin Gislason Avatar answered Nov 03 '22 22:11

Colin Gislason