You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by QiuyunZhong <qi...@hotmail.com> on 2006/07/27 16:12:14 UTC

sendRedirect throws illegalstateexception

Hey,guys,I know there are some question related to
illegalstateexception,however i've searched the forum for whole day and
still cann't solve the problem.
This is  the description of my problem:
  I added a phaselistener in web.xml to control user's visit of our web
site.The listener just implements this function:when user doesn't sign on
the site,it  redirects user to the signon.jsf page.
 Then we used code like this:

	if (identity == null)
		{
			
			if (!request.getRequestURI().endsWith("EmployeeSignOn.jsf")
					&& event.getPhaseId().equals(PhaseId.RENDER_RESPONSE))
			{
				
org.apache.catalina.connector.ResponseFacade response =
(ResponseFacade)FacesContext.getCurrentInstance().getExternalContext()
.getResponse();
try
{
						response.sendRedirect(DEFAULT_URL);
}catch( Exception e).....
in afterPhase function

However,it throws illegalStateException,I traced on ResponseFacade,it showed
the response is  commited.

The code is simple,and i don't know when the response is commited,i havn't
called responseComplete yet.I think this may be caused by my confuzed
understand of the lifecycle.
Any one can give me some hint or other method to implement the requirement?
Thanks a lot.
-- 
View this message in context: http://www.nabble.com/sendRedirect-throws-illegalstateexception-tf2009802.html#a5521786
Sent from the MyFaces - Users forum at Nabble.com.


Re: sendRedirect throws illegalstateexception

Posted by Andrew Robinson <an...@gmail.com>.
Put breakpoints in the HttpServletResponse code or the sub class if someone
has wrapped the "real one" or build your own wrapper that uses "
System.out.println" in the addHeader/setHeader methods.

(there is no easy way besides debugging).

The other alternative is to remove all of your phase listeners and servlet
filters and if that fixes the problem, add them back 1 by 1 until the
problem occurs again.

On 7/27/06, QiuyunZhong <qi...@hotmail.com> wrote:
>
>
> we just use one phaselistener defined in faces-config.xml
>         <lifecycle>
>                 <phase-listener>
>                         base.presentation.common.ShowPhaseListener
>                 </phase-listener>
>         </lifecycle>
> and one extension filter(i think it won't effect the response,right?)
>
>    <filter>
>         <filter-name>extensionsFilter</filter-name>
>
> <filter-class>org.apache.myfaces.component.html.util.ExtensionsFilter
> </filter-class>
> </filter>
> How can i know whether there is something wrote to the header before
> redirection?
> Thank you.
>
> --
> View this message in context:
> http://www.nabble.com/sendRedirect-throws-illegalstateexception-tf2009802.html#a5523699
> Sent from the MyFaces - Users forum at Nabble.com.
>
>

Re: sendRedirect throws illegalstateexception

Posted by QiuyunZhong <qi...@hotmail.com>.
we just use one phaselistener defined in faces-config.xml
	<lifecycle>
		<phase-listener>
			base.presentation.common.ShowPhaseListener
		</phase-listener>
	</lifecycle>
and one extension filter(i think it won't effect the response,right?)

   <filter>
        <filter-name>extensionsFilter</filter-name>
       
<filter-class>org.apache.myfaces.component.html.util.ExtensionsFilter</filter-class>
</filter>
How can i know whether there is something wrote to the header before
redirection?
Thank you.

-- 
View this message in context: http://www.nabble.com/sendRedirect-throws-illegalstateexception-tf2009802.html#a5523699
Sent from the MyFaces - Users forum at Nabble.com.


Re: sendRedirect throws illegalstateexception

Posted by Andrew Robinson <an...@gmail.com>.
Do you have any filters or phase listeners that would be committing the
response? If any filters or phase listeners that run before your redirect
call set any HTTP headers or print any kind of output you will not be able
to redirect.

On 7/27/06, QiuyunZhong <qi...@hotmail.com> wrote:
>
>
> RENDER_RESPONSE,however, no matter whether i sendirect in phase
> RESTOR_VIEW
> or RENDER_RESPONSE,it throws the exception.
> when i redirect in RENDER_RESPONSE phase,it issues the exception and
> doesn't
> rediret the page;
> when i try to redirect in RESTORE_VIEW,the exception is still
> issued,however
> the page is redirected to the signon.jsf.
> Following is the stacktrace,hope them can give some hints:
> 23:11:28,390 INFO  [STDOUT] java.lang.IllegalStateException
> 23:11:28,390 INFO  [STDOUT]     at
> org.apache.catalina.connector.ResponseFacade.sendRedirect(
> ResponseFacade.java:423)
> 23:11:28,390 INFO  [STDOUT]     at
> base.presentation.common.ShowPhaseListener.afterPhase(
> ShowPhaseListener.java:59)
> 23:11:28,390 INFO  [STDOUT]     at
>
> org.apache.myfaces.lifecycle.PhaseListenerManager.informPhaseListenersAfter
> (PhaseListenerManager.java:89)
> 23:11:28,390 INFO  [STDOUT]     at
> org.apache.myfaces.lifecycle.LifecycleImpl.restoreView(LifecycleImpl.java
> :181)
> 23:11:28,390 INFO  [STDOUT]     at
> org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:66)
> 23:11:28,390 INFO  [STDOUT]     at
> javax.faces.webapp.FacesServlet.service(FacesServlet.java:146)
> Thanks in advance!
> --
> View this message in context:
> http://www.nabble.com/sendRedirect-throws-illegalstateexception-tf2009802.html#a5523055
> Sent from the MyFaces - Users forum at Nabble.com.
>
>

Re: sendRedirect throws illegalstateexception

Posted by QiuyunZhong <qi...@hotmail.com>.
RENDER_RESPONSE,however, no matter whether i sendirect in phase RESTOR_VIEW
or RENDER_RESPONSE,it throws the exception.
when i redirect in RENDER_RESPONSE phase,it issues the exception and doesn't
rediret the page;
when i try to redirect in RESTORE_VIEW,the exception is still issued,however
the page is redirected to the signon.jsf.
Following is the stacktrace,hope them can give some hints:
23:11:28,390 INFO  [STDOUT] java.lang.IllegalStateException
23:11:28,390 INFO  [STDOUT] 	at
org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:423)
23:11:28,390 INFO  [STDOUT] 	at
base.presentation.common.ShowPhaseListener.afterPhase(ShowPhaseListener.java:59)
23:11:28,390 INFO  [STDOUT] 	at
org.apache.myfaces.lifecycle.PhaseListenerManager.informPhaseListenersAfter(PhaseListenerManager.java:89)
23:11:28,390 INFO  [STDOUT] 	at
org.apache.myfaces.lifecycle.LifecycleImpl.restoreView(LifecycleImpl.java:181)
23:11:28,390 INFO  [STDOUT] 	at
org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:66)
23:11:28,390 INFO  [STDOUT] 	at
javax.faces.webapp.FacesServlet.service(FacesServlet.java:146)
Thanks in advance!
-- 
View this message in context: http://www.nabble.com/sendRedirect-throws-illegalstateexception-tf2009802.html#a5523055
Sent from the MyFaces - Users forum at Nabble.com.


Re: sendRedirect throws illegalstateexception

Posted by Cagatay Civici <ca...@gmail.com>.
Hi,

Which phase is it?

Cagatay

On 7/27/06, QiuyunZhong <qi...@hotmail.com> wrote:
>
>
> Hey,guys,I know there are some question related to
> illegalstateexception,however i've searched the forum for whole day and
> still cann't solve the problem.
> This is  the description of my problem:
>   I added a phaselistener in web.xml to control user's visit of our web
> site.The listener just implements this function:when user doesn't sign on
> the site,it  redirects user to the signon.jsf page.
> Then we used code like this:
>
>         if (identity == null)
>                 {
>
>                         if (!request.getRequestURI().endsWith("
> EmployeeSignOn.jsf")
>                                         && event.getPhaseId().equals(
> PhaseId.RENDER_RESPONSE))
>                         {
>
> org.apache.catalina.connector.ResponseFacade response =
> (ResponseFacade)FacesContext.getCurrentInstance().getExternalContext()
> .getResponse();
> try
> {
>                                                 response.sendRedirect
> (DEFAULT_URL);
> }catch( Exception e).....
> in afterPhase function
>
> However,it throws illegalStateException,I traced on ResponseFacade,it
> showed
> the response is  commited.
>
> The code is simple,and i don't know when the response is commited,i havn't
> called responseComplete yet.I think this may be caused by my confuzed
> understand of the lifecycle.
> Any one can give me some hint or other method to implement the
> requirement?
> Thanks a lot.
> --
> View this message in context:
> http://www.nabble.com/sendRedirect-throws-illegalstateexception-tf2009802.html#a5521786
> Sent from the MyFaces - Users forum at Nabble.com.
>
>