I have a Facelets(JSF 1.2 (myfaces)) web app and I want to customize my error page - which would seem to be a natural thing to do when an application matures. I got really confused in the process.
I found the following:
I haven't found a way to customize Facelets' error page. I haven't found where the template is. I have found solutions with overriding the ViewHandler that would do sendRedirect(). I think this should be accomplishable without writing code, especially the ViewHandler.
I have found a way to switch off Facelets' error handling and using myFaces' one:
code:
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.ERROR_HANDLING</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.ERROR_TEMPLATE_RESOURCE</param-name>
<param-value>/pages/public/errorPage.jsf</param-value>
</context-param>
Unfortunately I cannot seem to make myFaces find a JSF page. I need to use a jsf page because I want to use the site's layout which is fragmented over a few templates. Source: http://wiki.apache.org/myfaces/Handling_Server_Errors
web.xml:
<context-param>
<param-name>org.apache.myfaces.ERROR_HANDLING</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.ERROR_HANDLER</param-name>
<param-value>org.apache.myfaces.tomahawk.util.ErrorRedirectJSFPageHandler</param-value>
</context-param>
faces-config.xml:
<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-outcome>java.lang.Throwable</from-outcome>
<to-view-id>/pages/public/errorPage.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
Source: http://wiki.apache.org/myfaces/Handling_Server_Errors
<error-page>
in web.xml
. I successfully forwarded to a jsf error page. Here the problem is that I cannot display the Exception - I don't know how.Update: I found out how - with a ManagedBean:
public class ErrorDisplayBean {
public String getStackTrace() {
FacesContext context = FacesContext.getCurrentInstance();
Map requestMap = context.getExternalContext().getRequestMap();
Throwable ex = (Throwable) requestMap.get("javax.servlet.error.exception");
...
}
}
see http://wiki.apache.org/myfaces/Handling_Server_Errors for the rest of the code.
What I want to accomplish: I want to use Facelets' error-handling mechanism without writing code and be able to display the Exception on a jsf page. If that is not possible, I'd like to use myFaces' error-handling again with displayin the Exception. I think one of them should be possible.
I think you can still make of configuration through your web.xml:
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error.xhtml</location>
</error-page>
Which can be used for error codes too..