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 expects its description in the request scope. The page which wants to report failure or success can specify the request scope.

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 displayed for the field to which it is bound. The error message displays only if there is a problem with that specific field. The Display Errors component inserts an error message that is displayed for all fields on a form. The error message displays any time there is a problem on the page.

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 tasks
Creating an input form connected to a data source
Adding input components to a Faces JSP page
Adding selection lists to a Faces JSP file
Adding hyperlinks to a Faces JSP file
Using navigation rules with Faces JSP pages
Using File Upload components
Creating a Faces JSP file
Related reference
Panel - Form Box
Display Error
Display Errors

Feedback