The Java EE 5 Tutorial

Referencing Error Messages

A JavaServer Faces page uses the message or messages tags to access error messages, as explained in Displaying Error Messages with the message and messages Tags.

The error messages that these tags access include:

When a converter or validator is registered on an input component, the appropriate error message is automatically queued on the component.

A page author can override the error messages queued on a component by using the following attributes of the component’s tag:

All three attributes are enabled to take literal values and value expressions. If an attribute uses a value expression, this expression references the error message in a resource bundle. This resource bundle must be made available to the application in one of the following ways:

Conversely, the message-bundle element must be used to make available to the application those resource bundles containing custom error messages that are queued on the component as a result of a custom converter or validator being registered on the component.

The bookcashier.jsp page includes an example of the requiredMessage attribute using a value expression to reference an error message:

<h:inputText id="ccno" size="19"
    requiredMessage="#{customMessages.ReqMessage}" >
<h:message styleClass="error-message"  for="ccno"/>

The value expression that requiredMessage is using in this example references the error message with the ReqMessage key in the resource bundle, customMessages.

This message replaces the corresponding message queued on the component and will display wherever the message or messages tag is placed on the page.

See Registering Custom Error Messages and Registering Custom Localized Static Text for information on how to use the message-bundle and resource-bundle element to register resource bundles that contain error messages.