I am using a phase listener to manage things like logon and conversation scope. In some situations I want to redirect. The most obvious is when the user is not logged on and they are attempting to access a protected page.
Currently my PhaseListener runs After Restore View. This is sometimes too late. When the user logs off the page is disposed and they are redirected back to the logon page. That page disposal causes some AJAX events in IceFaces – only I’ve destroyed the session so beans are missing state. This causes exceptions during Restore View, which appears to access the backing bean through EL in the page.
If I move my phase listener to Before Restore View and attempt to redirect using the ExternalContext I end up with a NullPointerException.
java.lang.NullPointerException
com.sun.faces.lifecycle.RestoreViewPhase.notifyAfter(RestoreViewPhase.java:301)
com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:114)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:67)
com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:118)
One option I could use would be use use a Servlet Filter for this work. It would also cover non-JSF requests. I don’t know how much of JSF will be available (and how much I actually need) in this case and it is not immediately clear how I cam make my filter happen after things like the ConversationPropagationFilter and before PrettyFilter.
Thanks
– Richard
That’s an old bug which is already been fixed in Mojarra 2.1 . The source of
RestoreViewPhase#notifyAfter()method of for example Mojarra 2.0.2 says the following:which means that
viewRootisnull. That can happen ifFacesContext#responseComplete()is been called before that point, which in turn is implicitly done byExternalContext#rediect(). After Mojarra 2.1, a nullcheck onviewRootis been added which fixes this bug.So, upgrade to at least Mojarra 2.1. It’s currently already at 2.1.4.
As to your (unrelated) note:
JSF stores managed beans and a lot of other information as attributes of
HttpSessionandServletContext, all which are available in theFilter. So that should be doable. As to the filter invocation order; that’s just controllable by the<filter-mapping>order inweb.xml.