Re: Issue using Facelets and Error Pages

View: New views
2 Messages — Rating Filter:   Alert me  

Parent Message unknown Re: Issue using Facelets and Error Pages

by Mario Rodriguez-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi, I'm using JSF with Facelets and I'm trying to use standard error pages but they doesn't seem to work with facelets, only in normal JSP pages. Is this combination valid? if not, how facelets is supposed to handle error pages ?

Any idea is welcome.

Here is my web.xml:

Code:
   <error-page>
<exception-type>javax.faces.el.EvaluationException</exception-type>
<location>/AppError.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/AppError.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/AppError.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/AppError.jsp</location>
</error-page>

And my facelet page:

Code:
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
<h:form id="myForm" >
<h:commandButton value="Cause a NullPointerException" actionListener="#{authorizationBean.doSomethingNull}"/>
</h:form>
</body>
</html>

It calls a authorizationBean.doSomethingNull method that explicitly forces a NUllpointerException to be thrown.


AppError.jsp is a plain JSP page:

Code:
 <%@ page isErrorPage="true" %>
<HTML>
<HEAD>
<TITLE>Error Information</TITLE>
</HEAD>

<BODY>

An error occurred during processing!<br><br>

</BODY>
</HTML>
And the exception displayed on the App Server console and not properly handled by the Error page is :

[1/19/09 15:26:26:681 CST] 00000028 jsf           E com.sun.faces.lifecycle.InvokeApplicationPhase execute /index.jspx @20,116 actionListener="#{authorizationBean.doSomethingNull}": java.lang.NullPointerException: Just a test...
                                 javax.faces.el.EvaluationException: /index.jspx @20,116 actionListener="#{authorizationBean.doSomethingNull}": java.lang.NullPointerException: Just a test...
    at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:73)
    at javax.faces.component.UICommand.broadcast(UICommand.java:305)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:302)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:419)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)
    at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:220)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:91)

Mario Rodriguez



Parent Message unknown RE: Re: Issue using Facelets and Error Pages

by Raymond K. DeCampo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

We've done this kind of thing with no problems.  I recall there was a discussion, perhaps on the Sun JSF forums, concerning a bug with some combination of JSF implementation and application server where the exceptions were being wrapped in ServletExceptions (or something) and then not being interpreted properly by the container for the error page mechanism.
 
-----Original Message-----
From: Mario Rodriguez [mailto:rvillane@...]
Sent: Monday, January 19, 2009 16:59
To: users@...
Subject: Re: Issue using Facelets and Error Pages


Hi, I'm using JSF with Facelets and I'm trying to use standard error pages but they doesn't seem to work with facelets, only in normal JSP pages. Is this combination valid? if not, how facelets is supposed to handle error pages ?

Any idea is welcome.

Here is my web.xml:

Code:
   <error-page>
<exception-type>javax.faces.el.EvaluationException</exception-type>
<location>/AppError.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/AppError.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/AppError.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/AppError.jsp</location>
</error-page>

And my facelet page:

Code:
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
<h:form id="myForm" >
<h:commandButton value="Cause a NullPointerException" actionListener="#{authorizationBean.doSomethingNull}"/>
</h:form>
</body>
</html>

It calls a authorizationBean.doSomethingNull method that explicitly forces a NUllpointerException to be thrown.


AppError.jsp is a plain JSP page:

Code:
 <%@ page isErrorPage="true" %>
<HTML>
<HEAD>
<TITLE>Error Information</TITLE>
</HEAD>

<BODY>

An error occurred during processing!<br><br>

</BODY>
</HTML>
And the exception displayed on the App Server console and not properly handled by the Error page is :

[1/19/09 15:26:26:681 CST] 00000028 jsf           E com.sun.faces.lifecycle.InvokeApplicationPhase execute /index.jspx @20,116 actionListener="#{authorizationBean.doSomethingNull}": java.lang.NullPointerException: Just a test...
                                 javax.faces.el.EvaluationException: /index.jspx @20,116 actionListener="#{authorizationBean.doSomethingNull}": java.lang.NullPointerException: Just a test...
    at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:73)
    at javax.faces.component.UICommand.broadcast(UICommand.java:305)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:302)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:419)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)
    at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:220)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:91)

Mario Rodriguez