10 Replies Latest reply on Apr 7, 2010 11:16 AM by Adam Warski

    Using events instead of a PhaseListener

    Adam Warski Master

      I have a PhaseListener, which executes some code before the RENDER_RESPONSE phase. Sometimes it does a redirect, using facesCtx.getExternalContext().redirect(url). And this works fine.


      However, if I try to execute the same code, but observe the before render response events, it stops working.


      The signature for my method is:


      public void beforePhase(@Observes @Before @RenderResponse PhaseEvent event)



      And the exception I get:


      java.lang.IllegalStateException
           org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:436)
           javax.servlet.http.HttpServletResponseWrapper.sendRedirect(HttpServletResponseWrapper.java:170)
           javax.servlet.http.HttpServletResponseWrapper.sendRedirect(HttpServletResponseWrapper.java:170)
           org.jboss.weld.servlet.ConversationPropagationFilter$1.sendRedirect(ConversationPropagationFilter.java:91)
           com.sun.faces.context.ExternalContextImpl.redirect(ExternalContextImpl.java:572)
           util.SecurityPhaseListener.beforePhase(SecurityPhaseListener.java:38)



      Any ideas why this happens only when I observe the phase events? Or where to start debugging? :)


      Adam