If I have an exception in my business layer (e.g. a SQL exception in my JDBC connection bean), how can I propagate it with a custom message to a global error.jsp
pa
JSF 1.x doesn't provide any implicit error handling of this type, though you can redirect to an error page using navigation rules (assuming a form post)...
Handle a generic error outcome that might be returned
by any application Action.
Generic Error Outcome
loginRequired
/must-login-first.jsp
...or using a redirect...
FacesContext context = FacesContext.getCurrentInstance();
ExternalContext extContext = context.getExternalContext();
String url = extContext.encodeActionURL(extContext
.getRequestContextPath()
+ "/messages.faces");
extContext.redirect(url);
I recommend looking at the JSF specification for more details.
Error messages can be placed on the request scope/session scope/url parameters, as you like.
Assuming a Servlet container, you can use the usual web.xml error page configuration.
java.lang.Exception
/errorPage.faces
In your backing bean, you can wrap and throw your checked exceptions in RuntimeExceptions.
Some JSF implementations/frameworks will catch these errors (Apache MyFaces/Facelets), so you'll have to configure them not to.