O'Reilly logo

JavaServer Faces by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Debugging and Error Handling Ideas

JSF is such a new technology that very few best practices for debugging and error handling have emerged yet, but let's look at some possibilities.

Using Standard Java Debugging Techniques

Because JSF lends itself to a design where application logic is implemented as plain Java classes, all the usual techniques—such as Java debuggers and JUnit[3] test cases—can be used for a large part of the application.

Using Standard Web Application Error Handling

A JSF application is also a servlet-based application, so truly exceptional runtime exceptions can be trapped and handled by error handlers declared in the web.xml file:

<web-xml>
  ...
  <error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/errorpage.jsp</location>
  </error-page>
  ...
</web-xml>

The <error-page> element contains an <exception-type> element that names an exception type and a <location> element with a context-relative path for the resource to invoke if the exception is thrown by any request. The resource can be a JSP page or servlet that displays a friendly message instead of the stack trace most web containers show by default. It can also log information about the error, available as request scope attributes as well as through the implicit pageContext variable in a JSP page. If you need to deal with different types of exceptions in different ways, you can declare more than one error handler. The web container picks the one with an exception type that most closely matches ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required