Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I get a similar set of errors. Following the above approach, my handle navigation</p> <pre><code>nav.handleNavigation(fc, null, "/error"); </code></pre> <p>Returns a NPE like above (same line numbers even).</p> <p>If I modify to just do a re-direct, I get:</p> <pre><code>java.lang.NullPointerException at org.apache.myfaces.context.servlet.PartialViewContextImpl.getPartialResponseWriter(PartialViewContextImpl.java:303) at org.primefaces.context.PrimePartialViewContext.getPartialResponseWriter(PrimePartialViewContext.java:45) at org.apache.myfaces.context.servlet.ServletExternalContextImpl.redirect(ServletExternalContextImpl.java:452) at my.package.CustomExceptionHandler.handle(CustomExceptionHandler.java:134) at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:191) at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189) at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1235) at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:758) at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:441) </code></pre> <p>In both cases I believe the cause is that the <code>getViewRoot()</code> is null which is apparently not expected by 'getNavigationCase' or <code>getPartialResponseWriter</code>.</p> <p>I was able to fix using the example at this blog post (<a href="http://ovaraksin.blogspot.com/2010/10/jsf-ajax-redirect-after-session-timeout.html" rel="nofollow">http://ovaraksin.blogspot.com/2010/10/jsf-ajax-redirect-after-session-timeout.html</a>). Seems that Mojarra and PrimeFaces (I am using PrimeFaces 3.5 with MyFaces) have issues with the standard re-direct in the case of this error. The fix is in the case that</p> <pre><code>facescontext.getResponseWriter() == null &amp;&amp; facescontext.getRenderKit() == null </code></pre> <p>and it's a partial request and an ajax request, then use the <code>RenderKit</code> to create a <code>ResponseWriter</code> and set it on the <code>facescontext</code>.</p> <p>The <code>externalContext.redirect()</code> then works.</p> <p>Edit: more specifically, in the blog post, the <code>SecurityPhaseListener</code> has a <code>doRedirect(FacesContext fc, String redirectPage)</code> method which includes a section called:</p> <pre><code> // fix for renderer kit (Mojarra's and PrimeFaces's ajax redirect) </code></pre> <p>I lifted that section into a redirect response method that I call from the block of <code>if (exception instanceof ViewExpiredException)</code></p> <p><strong>EDIT</strong> OK, final solution. With help from a sliver of code from <a href="http://jira.icesoft.org/browse/ICE-4251" rel="nofollow">http://jira.icesoft.org/browse/ICE-4251</a> I was able to implement this using the handlenavigation. Here is the call I added from the JIRA issue which gets executed in the handle()</p> <pre><code>checkViewRoot(facesContext,"/error.jsf"); </code></pre> <p>... Here is the method</p> <pre><code> public static void checkViewRoot( FacesContext ctx, String viewId) { if (ctx.getViewRoot() == null) { UIViewRoot viewRoot = ctx.getApplication().getViewHandler().createView(ctx, viewId); if (viewRoot != null) { ctx.setViewRoot(viewRoot); } } } </code></pre> <p>... And after that, handlenavigation is called in the handle() method.</p> <pre><code> facesContext .getApplication() .getNavigationHandler() .handleNavigation(facesContext, null, (redirectPage != null ? redirectPage : "")); facesContext.renderResponse(); </code></pre> <p>Note that in my experience thus far, <code>viewId</code> must be an existing page and different than the one to which you need to re-direct.</p> <p>Nice thing is the <code>facesmessage</code> I set with the <code>viewexpiredexception</code> message now displays on the new page which I was having all kinds of trouble with before with the redirect.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload