When and How to redirect to a view in a JSF Application

Redirecting to a View

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.


Comments:

Hi Jayshri I need some help here. I'm using 'validator' attribute on some 'immediate' and non-immediate UIInput 'Select' & Text components. Code: validator="#{adjustmentDetail.validate}" While the page is submitted (non-immediate command button type="submit"), this method is called as expected for all non-immediate components but for immediate components it never gets called. I'm not able to understand the exact problem, please see if you can provide a hint. Thanks Ravi

Posted by Ravindra Maurya on June 11, 2007 at 12: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 02:07 AM PDT #

a

Posted by guest on April 07, 2009 at 10:05 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

jayashri

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today