Skip to main content

JSF: user exception thrown in action won't show web.xml error page

1 reply [Last post]
healeyb
Offline
Joined: 2010-01-26
Points: 0

(edited h:commandButton action= NOT actionListener=)

Hi,

I've got a JSF (2.02-10) app on a GlassFish v3 stack and am trying to direct a
user defined exception thrown by an action method to an error page defined in the
web.xml file. What happens is that the default HTTP 500 error page is navigated
to instead of the page that I have specified.

web.xml extract
-----------------------

uk.co.myco.exceptions.MyTestException
/faces/errorPage.xhtml

My exception declaration
-------------------------------------
public class MyTestException extends Exception { ... constructors... }

Just to test this functionality I added an h:commandButton to a JSF page which
calls an action= method which throws the
MyTestException as follows:

public String testExceptionAction() throws MyTestException {
throw new MyTestException("hello");
}

I get the default GlassFish HTTP 500 error page as shown:

HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: uk.co.myco.exceptions.MyTestException
root cause

javax.faces.el.EvaluationException: uk.co.myco.exceptions.MyTestException
root cause

uk.co.myco.exceptions.MyTestException
note The full stack traces of the exception and its root causes are available in the GlassFish v3 logs.
--------------------------------------------------------------------------------

It's as if the Faces Servlet is catching my MyTestException and re-throwing a
ServletException. Can anyone suggest what I should be doing to get this working?

If I change the entry in web.xml to either ServletException OR
EvaluationException then the page I have specified is navigated to successfully.

Thanks for any suggestions, this problem has been hanging around on my "not
working right" list for a while now and it'd be nice to put a solid workaround in
place (i.e. changing the default error pages) if this functionality just doesn't work.

Regards,
Brendan.

Message was edited by: healeyb

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mpscholz
Offline
Joined: 2003-06-12
Points: 0

Not completely sure about that, but with JSF, wouldn't you need to write a custom exception handler for your own application exceptions that are not catched directly in your application?

For ServletException and EvaluationException, it works out of the box, as these belong to a type of exception JSF takes care by itself.