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:
- Custom JSF messages:
If an annotation uses the default JSF message, it's possible to customize the default JSF message.
(Use the standard mechanism of JSF.)
- Convention:
Create a new message bundle with the file name: validation_messages.properties
in the package: org.apache.myfaces.extensions.validator.custom (A simple demo is available here: demo_001)
- Managed Bean approach:
Provide a custom InformationProviderBean and register it.
(A simple demo is available here: demo_004) This approach is recommendable, if you have to customize several parts via the information provider bean.
- Message resolver:
- web.xml configuration:
Add a context-param to you web.xml
param-name: org.apache.myfaces.extensions.validator.CUSTOM_MESSAGE_BUNDLE
param-value: package + message bundle name (e.g.: org.apache.myfaces.blank.custom_messages)
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:
(A simple demo is available here: demo_001 - see the custom message key at the cross-validation annotation.)