This blog discusses the reason and fix for the IllegalStateException (IAE) that you may run into when you call FacesContext.getExternalContext().redirect() in your JSF application.
During RenderResponse phase, the JSF framework (ViewHandler in particular) does a RequestDispatcher.forward() to the specified view and the response is sent to the client. So if you do a redirect after the response has been committed, (say in the afterRenderResponse() , you will get an IAE. In other words, you can call redirect() instead of rendering the page and not after rendering the page. If you do so, Servlet Container will throw an exception because the call to forward() during RenderResponse phase would have already committed the response. So the right time to do the redirect would be anytime before the RenderResponse phase executes namely preRender(), (if you are in JavaStudio Creator) or beforeRenderResponse(). You also need to call FacesContext.responseComplete() after you call redirect() to indicate to the JSF framework that the response has been committed, so RenderResponse phase can be skipped.
Posted by Ravindra Maurya on June 11, 2007 at 07:39 AM PDT #
Hi,
I have feq questions regarding the to redirect to view in JSF application.
1) I have a struts application which launches other struts application using below code is shown. Below code is in Action class
String approvalURL = "/example.do";
RequestDispatcher dispatcher= getServletContext().getRequestDispatcher(approvalURL);
2) Then I'm migrating second struts application to JSF
Then how should i launch the JSF System in Struts System, I need a example with code in Action class how to invoke the JSF system.
Waiting for your valuable response.
Regards,
Ravi
Posted by Ravi Reddy on April 08, 2008 at 09:07 AM PDT #
a
Posted by 193.63.117.253 on April 08, 2009 at 05:05 AM PDT #