Differences between revisions 10 and 11
Revision 10 as of 2008-11-13 21:07:15
Size: 4234
Comment:
Revision 11 as of 2009-09-20 23:00:46
Size: 4254
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:
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[[BR]] 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<<BR>>
Line 9: Line 9:
There are several possibilities to override the default message of an annotation.[[BR]] There are several possibilities to override the default message of an annotation.<<BR>>
Line 14: Line 14:
   If an annotation uses the default JSF message, it's possible to customize the default JSF message.[[BR]]    If an annotation uses the default JSF message, it's possible to customize the default JSF message.<<BR>>
Line 18: Line 18:
   Create a new message bundle with the file name: '''validation_messages.properties'''[[BR]]    Create a new message bundle with the file name: '''validation_messages.properties'''<<BR>>
Line 20: Line 20:
   (A simple demo is available here: [http://code.google.com/p/os890/source/browse/#svn/trunk/java/web/jsf/extval/examples/advanced/demo_001 demo_001])    (A simple demo is available here: [[http://code.google.com/p/os890/source/browse/#svn/trunk/java/web/jsf/extval/examples/advanced/demo_001|demo_001]])
Line 23: Line 23:
   Provide a custom InformationProviderBean and register it.[[BR]]
   (A simple demo is available here: [http://code.google.com/p/os890/source/browse/#svn/trunk/java/web/jsf/extval/examples/advanced/demo_004 demo_004])
   Provide a custom InformationProviderBean and register it.<<BR>>
   (A simple demo is available here: [[http://code.google.com/p/os890/source/browse/#svn/trunk/java/web/jsf/extval/examples/advanced/demo_004|demo_004]])
Line 30: Line 30:
   [http://code.google.com/p/os890/source/browse/#svn/trunk/java/web/jsf/extval/examples/advanced/demo_005 demo_005],
   [http://code.google.com/p/os890/source/browse/#svn/trunk/java/web/jsf/extval/examples/advanced/demo_104 demo_104],
   [http://code.google.com/p/os890/source/browse/#svn/trunk/java/web/jsf/extval/examples/advanced/demo_105 demo_105])
   [[http://code.google.com/p/os890/source/browse/#svn/trunk/java/web/jsf/extval/examples/advanced/demo_005|demo_005]],
   [[http://code.google.com/p/os890/source/browse/#svn/trunk/java/web/jsf/extval/examples/advanced/demo_104|demo_104]],
   [[http://code.google.com/p/os890/source/browse/#svn/trunk/java/web/jsf/extval/examples/advanced/demo_105|demo_105]])
Line 35: Line 35:
   Add a context-param to you web.xml[[BR]]
   param-name: '''org.apache.myfaces.extensions.validator.CUSTOM_MESSAGE_BUNDLE'''[[BR]]
   Add a context-param to you web.xml<<BR>>
   param-name: '''org.apache.myfaces.extensions.validator.CUSTOM_MESSAGE_BUNDLE'''<<BR>>
Line 40: Line 40:
[key_name] for the summary and [key_name]_detail for the details (like the standard JSF convention).[[BR]]
e.g.:[[BR]]
field_required=required[[BR]]
[key_name] for the summary and [key_name]_detail for the details (like the standard JSF convention).<<BR>>
e.g.:<<BR>>
field_required=required<<BR>>
Line 47: Line 47:
Again, you can customize the standard JSF messages.[[BR]] Again, you can customize the standard JSF messages.<<BR>>
Line 50: Line 50:
'''Or''' you can use a special web.xml context-param to provide a custom bundle for JPA validation error messages:[[BR]] '''Or''' you can use a special web.xml context-param to provide a custom bundle for JPA validation error messages:<<BR>>
Line 55: Line 55:
(A simple demo is available here: [http://code.google.com/p/os890/source/browse/#svn/trunk/java/web/jsf/extval/examples/basic/demo_001 demo_001] - see the StartupListener) (A simple demo is available here: [[http://code.google.com/p/os890/source/browse/#svn/trunk/java/web/jsf/extval/examples/basic/demo_001|demo_001]] - see the StartupListener)
Line 58: Line 58:
(A simple demo is available here: [http://code.google.com/p/os890/source/browse/#svn/trunk/java/web/jsf/extval/examples/advanced/demo_105 demo_105]) (A simple demo is available here: [[http://code.google.com/p/os890/source/browse/#svn/trunk/java/web/jsf/extval/examples/advanced/demo_105|demo_105]])
Line 66: Line 66:
e.g.:[[BR]]
password_required=password required[[BR]]
e.g.:<<BR>>
password_required=password required<<BR>>
Line 70: Line 70:
And override the default key of the annotation.[[BR]] And override the default key of the annotation.<<BR>>
Line 73: Line 73:
attachment:myfaces-extval_examples_annotation_with_custom_message.png {{attachment:myfaces-extval_examples_annotation_with_custom_message.png}}
Line 75: Line 75:
(A simple demo is available here: [http://code.google.com/p/os890/source/browse/#svn/trunk/java/web/jsf/extval/examples/advanced/demo_001 demo_001] - see the custom message key at the cross-validation annotation.) (A simple demo is available here: [[http://code.google.com/p/os890/source/browse/#svn/trunk/java/web/jsf/extval/examples/advanced/demo_001|demo_001]] - see the custom message key at the cross-validation annotation.)

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:
    • If you would like to use the message resolver mechanism. You can provide your own message resolver. (A simple demo is available here:

      demo_005, demo_104, demo_105)

  • 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:

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)