Customizable Messages

ExtVal uses the JSF validation messages per default (as far as possible). Some of the ExtVal annotations provide a default message (via a default key). In case of @Required it's: field_required and field_required_detail
(In case of @Required it's an optional key.) (ExtVal also supports alternative resource types. The default format is the property file format.)

Provide your own default message

There are several possibilities to override the default message of an annotation.
The simplest way to do that is to provide a custom message bundle and override the default key.

Choose one of the following Possibilities:

You always should provide two messages (summary and details). The naming convention is: [key_name] for the summary and [key_name]_detail for the details (like the standard JSF convention).
e.g.:
field_required=required
field_required_detail=required

Provide custom JPA error messages

Again, you can customize the standard JSF messages.
(javax.faces.component.UIInput.REQUIRED and javax.faces.validator.LengthValidator.MAXIMUM)

Or you can use a special web.xml context-param to provide a custom bundle for JPA validation error messages:
org.apache.myfaces.extensions.validator.JPA_VALIDATION_ERROR_MESSAGES (Keys: field_required and field_too_long)

Or you can use the ExtVal Java API to register a bundle (A simple demo is available here: demo_001 - see the StartupListener)

Or you can also provide a custom message resolver for the JPA validation message. (A simple demo is available here: demo_105)

Reuse an existing message bundle

You just have to point to an existing message bundle within you application. It's the same procedure like above.

New custom Messages

Just add the new keys to your custom message bundle.

e.g.:
password_required=password required
password_required_detail=please enter a password

And override the default key of the annotation.
e.g:

myfaces-extval_examples_annotation_with_custom_message.png

(A simple demo is available here: demo_001 - see the custom message key at the cross-validation annotation.)

Extensions/Validator/Getting_Started/Custom_Messages (last edited 2009-09-20 23:00:46 by localhost)