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:
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
- Open a Faces JSP page.
- Drag a Display Error component to the page.
- 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.
- 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.
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.