myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kuhn, Harald" <>
Subject RE: Handling Server Errors
Date Wed, 04 Jun 2008 07:27:46 GMT

I struckled with the same problems (definition of JSF error pages in
On further debugging I realized that the problem lies in the postback
handling of JSF:

Lets say a postback zu View a.xhtml causes any error in some backing
Then the flow is as followed:

1) JSF Lifecyle of view a.xhtml starts
2) Exception is thrown (i.e. during InvokeApplication)
3) if no JSF error handlers are defined this exception pops up to tomcat
(Servlet-API) error handling
4) tomcat searches for error page in web.xml
5) tomcat forwards to the error-page
6) as the error page is also JSF, the JSF lifecycle for the error page
is started
7) In Phase RestoreView JSF checks if it is a postback
	As it is just a forward it is the same request as for 1)
	Therefore there is a postback token on the request and the view
corresponding to this token is restored.
	As this token is from the inital request/postback of view
a.xhtml, this view is restored.
8) as the JSF lifecycle continoues with view a.xhtml the exception is
reached a second time
9) as there are errors during error-handling, tomcat shows the standard

A solution that worked for our requirement is:

a) Create a custom FACES-Servlet that implements interface
DelegatedFacesServlet and delegates to the original FacesServlet
b) Register this servlet in your web.xml

The error handling works like this:
1) Catch all exception in the service-Method of the servlet
2) store the exception inside a session bean (or maybe page-flow is
sufficent as well)
3) redirect to error page
4) error page is loaded by browser and displays the stored exception
from session bean.

In this solution the error page is loaded by the browser and therefore
it is an initial request and no postback any more.

Hope this helps


-----Original Message-----
From: haric [] 
Sent: Tuesday, June 03, 2008 7:11 PM
Subject: Handling Server Errors

I am trying to write my own exception handler as per the details at 

I tried to override handleException(fc,ex) method as following
public void handleException(FacesContext fc, Exception ex) throws
	log.error("Exception occured...", ex);
	if(ex is of sometype){
		NavigationHandler nh =
		nh.handleNavigation(fc, null, "exceptionNavigation");
	} else {
		throw ex;

in web.xml

navigation rule

The handleException() method gets invoked but never redirects to
errorHtml.html for if case, and it also fails for else case. If I get
error 500 and as per web.xml it should redirect errorDisplay.xhtml
it shows whole stack trace on the web page.

The functionality I am looking is:
- Catch the exception in handleException() method
- log the error
- If error is certain type redirect to static html/jsf page using
- else throw the exception
- handle 500/404 and other exceptions using web.xml error pages
- if possible populate a bean with error messages or add messages to
FacesContext and redirect a standard jsf file where we display

I appreciate help on this.
View this message in context:
Sent from the MyFaces - Users mailing list archive at

View raw message