August 27, 2010

tapestry 5 custom validation error message

in our system/ configuration, in order to customize T5 validation messages using the T5 validation message language key conventions, i had to use the following language keys:
  • "required" as language key for a required field
    - f.ex. when i use t:validate="required" in a .tml file
  • "number-format-exception" for a number field, and integer-format-exception for an integer field
    - when an input field attached to an integer property gets a letter, f.ex. 
using "%s" in the language expression will give access to the name of the field, f.ex. having an error message like "%s must be completed".
    what did NOT work for us, even if it worked for others (ref information below), was any prefix with field or form name, or a postfix of -message...


    Apache Tapestry - Form Input and Validation:
    Customizing Validation Messages

    Each validator (such as "required" or "minlength") has a default message used (on the client side and the server side) when the constraint is violated; that is, when the user input is not valid.

    The message can be customized by adding an entry to the page's message catalog (or the containing component's message catalog). As with any localized property, this can also go into the application's message catalog.

    The first key checked is formId-fieldId-validatorName-message.
    • formId: the local component id of the Form component
    • fieldId: the local component id of the field (TextField, etc.)
    • validatorName: the name of the validator, i.e., "required" or "minlength"
    If there is not message for that key, a second check is made, for fieldId-validatorName-message.

    If that does not match a message, then the built-in default validation message is used.

    http://tapestry.1045711.n5.nabble.com/T5-Overriding-integer-validation-message-td2436931.html#a2436931:

    (from the answers)

    You should add a prefix consisting of the field id (and optionally the form 
    id).
    (Igor)

    To generalize messages overrides for all form, you can contribute to ValidationMessagesSource service in your AppModule class with your own
    property file. (Christophe)

    Trial and error have yielded: [field id]-integer-message  (xfile80303)
    Blogged with the Flock Browser

    No comments: