Pages

Sunday, May 06, 2012

JSF 2 Tip of the Day: JSF Page Redirection in PhaseListener

I needed to redirect a user to a login page the other day, and solved it using a PhaseListener. Subsequently, I had another need to do a page redirection based on a value in the HttpSession. I thought I would share the general idea of how to do it with you.

The PhaseListener allows us to take action at various integration points in the JSF lifecycle. The most likely place you will want to handle an internal redirection, is before the view is restored. We use the JSF NavigationHandler to do the work for us.

PageRedirectionPhaseListener.java

2 comments :