[ 
https://issues.apache.org/jira/browse/MYFACES-3673?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13554043#comment-13554043
 ] 

Leonardo Uribe commented on MYFACES-3673:
-----------------------------------------

Use RequestDispatcher will not work. Instead you can do this:

            FacesContext facesContext = FacesContext.getCurrentInstance();
            
facesContext.getApplication().getNavigationHandler().handleNavigation(
                    facesContext, null, "mypage?faces-redirect=true");

or you can something like this:

            FacesContext facesContext = FacesContext.getCurrentInstance();
            UIViewRoot root = facesContext.getApplication().
                getViewHandler().createView(facesContext, "mypage.xhtml");
            facesContext.setViewRoot(root);

The reason why RequestDispatcher will not work is that shortcut jsf lifecycle, 
so the forward occur and another lifecycle occur, but when the control come 
back, the inner lifecycle clear FacesContext thread local var.

In JSF 2.2, f:viewAction component will be included, fixing properly these kind 
of use cases.
                
> NullPointerException in FlashImpl when forwarding from an init action
> ---------------------------------------------------------------------
>
>                 Key: MYFACES-3673
>                 URL: https://issues.apache.org/jira/browse/MYFACES-3673
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: JSR-314
>    Affects Versions: 2.0.16
>         Environment: Windows Myfaces 2.0.16, Jetty 8.1.3.v20120416
>            Reporter: Andreas Wuest
>
> Hi,
> the following exception occurs when ich try to forward from an init action 
> the preRenderView phase:
> The xhtml page i call contains the following preRenderView listener:
> <f:metadata>
>       <f:event type="preRenderView" 
> listener="#{localizedInitializerView.init}" />
> </f:metadata>
> In the init Method of the listener i am performing a forward to a different 
> page with the following
> logic:
>     public void init() throws Exception {
>         // performs the forward
>         HttpServletResponse response =
>                 (HttpServletResponse) 
> FacesContext.getCurrentInstance().getExternalContext().getResponse();
>         HttpServletRequest request =
>                 (HttpServletRequest) 
> FacesContext.getCurrentInstance().getExternalContext().getRequest();
>         RequestDispatcher dispatcher = 
> request.getRequestDispatcher("localized.jsf");
>         dispatcher.forward(request, response);
>         // 
> FacesContext.getCurrentInstance().getExternalContext().redirect("localized.jsf");
>         FacesContext.getCurrentInstance().responseComplete();
>     }
> The result is strange, because the forward just works fine, however i am 
> always getting the following
> NullPointerException in the log file. Using a redirect instead of the forward 
> just works fine.
> java.lang.NullPointerException
>         at 
> org.apache.myfaces.shared.context.flash.FlashImpl.isKeepMessages(FlashImpl.java:389)
>         at 
> org.apache.myfaces.shared.context.flash.FlashImpl._saveMessages(FlashImpl.java:666)
>         at 
> org.apache.myfaces.shared.context.flash.FlashImpl.doPostPhaseActions(FlashImpl.java:270)
>         at 
> org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:251)
>         at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)
>         at 
> org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:598)
>         at 
> org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:486)
>         at 
> org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
>         at 
> org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524)
>         at 
> org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:233)
>         at 
> org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1065)
>         at 
> org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:413)
>         at 
> org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:192)
>         at 
> org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:999)
>         at 
> org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
>         at 
> org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:250)
>         at 
> org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149)
>         at 
> org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111)
>         at org.eclipse.jetty.server.Server.handle(Server.java:350)
>         at 
> org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:454)
>         at 
> org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:890)
>         at 
> org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:944)
>         at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:630)
>         at 
> org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:230)
>         at 
> org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:77)
>         at 
> org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:606)
> If you need more information about the problem or a testcase, please tell me.
>  Cheers,
> Andy

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to