Search code examples
jsferror-handlingcorruptionsession-bean

How can I gracefully handle JSF application failures?


If my JSF applications, I'll sometimes come across a bug that, for example, corrupts a user session bean somewhere and the user is stuck looking @ a bunch of java exception gobbly-gook on their screen. The only way they can fix this is to restart their browser.

Instead, I would like the application to handle something like this gracefully...basically by being able to catch any of these uncaught exceptions and display an error message (and or possibly contain a link to allow the user to logout/login so they don't have to restart their browser).

Is there a way for JSF to do this easily? If not, does anyone have a solution for this?


Solution

  • You can just create a custom error page and define its location in <error-page> in web.xml.

    E.g.

    <error-page>
        <exception-type>java.lang.Exception</exception-type>
        <location>/error.jsp</location>
    </error-page>
    

    You've all freedom to make it look like the way you want.