Error Handling

Hello

Any good pointers to documents describing proper error handling.

Not just navigation rules to an error.jsp file but also handling of runtime exceptions and exceptions in backing beans where you cannot use navigation rules (calling a method from JSF EL etc.).

I am developing jsr 168 portlets using jsf on websphere portal.

I can't get the error handling via web.xml to function and other places I can't manually make it go to an error.jsp in case of exceptions.

Any ideas and pointers to best practices will be appreciated.

/Chr

[580 byte] By [landboa] at [2007-10-2 18:51:01]
# 1

This seems to be a shortcoming of JSF, the lack of good declarative error/exception handling.

So far with JSF portlets (WebSphere Portal / JSR 168 like you), I've found the best solution is to use the error page directive in the JSP, like

<%@page errorPage="../error/GenericError.jsp" %>

I've also found that defining error pages in web.xml doesn't seem to work.

michael.lucasa at 2007-7-13 20:13:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

About the web.xml way - I have just heard from someelse that it is not supported in the portal environment.

Could you eleborate a bit about how you would do it?

Just let backing bean throw exceptions (runtime or checked?) and then get transferred to error page?

How can then get the exception displayed on the error page?

Thanks

landboa at 2007-7-13 20:13:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Handling errors with a JSF Error Page.. http://www.jroller.com/page/mert?entry=handling_errors_with_an_errror
mulderbabaa at 2007-7-13 20:13:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
I wrote a simple add-on OzFaces that includes declarative exception handling and navigation. You can download it from http://sourceforge.net/projects/optionzero/
Taka at 2007-7-13 20:14:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

You can handle errors by writing your own faces servlet.

1. Starting with Mert Catlikan's basic approach. see http://www.jroller.com/page/mert?entry=handling_errors_with_an_errror for the basic approach.

2. If you're using JSF 1.2, make the following changes -- add the factory definitions to the faces-config for the applicationfactory, facescontextfactory, lifecyclefactory and the renderkitfactory. If this doesn't work when initing the app, add the following to your servlet init method before the delegate.init call,

FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY, "com.sun.faces.context.FacesContextFactoryImpl");

FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY, "com.sun.faces.lifecycle.LifecycleFactoryImpl");

3. Write a contextlistener that implements ServletContextListener. Add it as a listener node into the web.xml.

4. Your web.xml needs to be updated to use the custom faces servlet instead of the default Faces Servlet. You must however also have a servlet definition for the default facesservlet -- leave it but give it a name like Old Faces Servlet. Do not map it. (Because the faces mapping will now go to your custom faces servlet.)

5. Add the init-param within your custom servlet mapping. The name if you started with Mert's example is errorPage. The value is the /<name of your errorpage>.

That should do it.

wbossonsa at 2007-7-13 20:14:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...