Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Error Page redirection is not working with JSF2.0

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Saloon Keeper
Posts: 23449
159
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ilayaraja Raju
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23449
159
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ErrorPage is fine in JSF. Just not JSF ErrorPages.

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
There are 10 kinds of people in this world. Those that understand binary get this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic