Managing errors in JavaServer Faces applications

There are a couple of ways to handle error management in your JavaServer Faces applications. You can use the following techniques to unify the error and success reporting across your entire Web site.

One way involves creating general purpose success and failure JSP files. For example, ok.jsp and error.jsp. In general, you can create a Faces JSP page which expects the error message and its description in the request scope, which can be specified by the page which wants to report failure or success.

Another way to handle error management is to use the Display Error and Display Errors components. The Display Error component inserts an error message that is conditionally displayed for the field it is bound to. The Display Errors component inserts an error message that is conditionally displayed for all fields on a form.

To add a Display Error component to a Faces JSP page and bind it to another component:

  1. Open a Faces JSP page.

  2. Drag a Display Error component to the page.

  3. In the Properties view for the Display Error component, next to Display error message for the component, select the ID of the component to which you want to bind this Display Error component.

  4. Use the Props field to specify or browse for style properties (such as color and font) for the error message. Use the Classes message field to specify or browse for a style sheet for the error message.
Some Faces components give you the option of automatically creating a Display Error component that is bound to that component. For example, when you create an Input component, you can automatically create a Display Error component by checking Display validation error messages in an error message control on the Validation tab of the Properties view for the input component. The new Display Error component is automatically bound to the Input component.

 

Related concepts

JavaServer Faces

 

Related tasks

Creating Faces applications - overview
Creating a Faces JSP file
Adding validation for Faces input components

Related reference
Faces components reference
Attributes for Faces components