aspose file tools*
The moose likes JSF and the fly likes Error Page redirection is not working with JSF2.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Error Page redirection is not working with JSF2.0" Watch "Error Page redirection is not working with JSF2.0" New topic
Author

Error Page redirection is not working with JSF2.0

Ilayaraja Raju
Greenhorn

Joined: May 11, 2008
Posts: 10
Dear Gurus,

I am trying to forward the request to the common error page (dc_error_page.xhtml) when I encounter an exception in the application.

The below is the change:

web.xml:

<error-page>
<exception-type>com.dsta.gebiz.datacleanser.util.DCException</exception-type>
<location>/faces/scripts/dc_error_page.xhtml</location>
</error-page>

In the controller:
inside the back bean method:--
throw new DCException();

DCException.java:

public class DCException extends FacesException{

public DCException()
{
}

public String getMessage()
{
return "DC Exception occured - Message";
}

public String toString(){
return "DC Exception occured";
}

}

But when I encounter an exception in the application, the request goes to DCException but it is not getting redirected to the error page.
Instead I am getting the below Error and goes to the 505 error:
SEVERE: DC Exception occured
javax.faces.el.EvaluationException: DC Exception occured
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:98)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98)
at javax.faces.component.UICommand.broadcast(UICommand.java:311)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1255)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:334)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:57)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:57)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.doIt(WebAppServletContext.java:3684)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3650)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2268)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2174)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1446)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)

Any pointers on this is greatly appreciated.

Many Thanks.
Ilaya


Regards,<br />Ilaya
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16137
    
  21

Your errorPage location is a resource path.

To render JSF, you have to have a URL, not a resource path. The difference is that a URL is a string that tells the appserver how to route requests and gives the app information on how to process them. A resource path, on the other hand, is what corresponds to a directory subtree and filename when you unzip a WAR.

They look a lot alike, but they're very different.

I don't think you can specify a URL as an errorPage in web.xml. ErrorPages and similar views dispatched by the appserver such as welcome pages and login pages are only declarable as resource paths, and therefore won't get routed through the webapp's URL processors. Most importantly, this means that the FacesServlet will not be called and therefore JSF pages aren't possible.

What I normally do is display the error on a normal JSP with a "Click HERE to continue" link containing a JSF URL.

Or, in cases, where I do require a JSF "error page", I manage the error as a View navigation instead of throwing an exception out to the container.


Customer surveys are for companies who didn't pay proper attention to begin with.
Ilayaraja Raju
Greenhorn

Joined: May 11, 2008
Posts: 10
Hi Tim,

Thanks for your reply.

So you mean redirection to the error page is not possible in JSF?

So I ll try to redirect in the controller (back bean) to the error page instead of creating a new exception and expect the we container to redirect to the error page.

I mean I will change the controller code as:


In the controller: (OLD)
inside the back bean method:--
throw new DCException();

In the controller: (NEW)
inside the back bean method:--
catch (Exception e){
redirect "dc_error_page";
}

Once again thanks for your reply.



Regards,
Ilaya
+65 90843640
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16137
    
  21

ErrorPage is fine in JSF. Just not JSF ErrorPages.

No, I don't use a redirect when handling errors. I use navigation:

Juan Martin Lopez Ochoteco
Greenhorn

Joined: Apr 14, 2009
Posts: 2
Hi, I'm having the same problem. What would be the way of configuring a generic error page?

I tried with:



and also:


But no one seems to work
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error Page redirection is not working with JSF2.0