Announcement Announcement Module
Collapse
No announcement yet.
Valang - localizing / customizing error messages Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Valang - localizing / customizing error messages

    I have a valang validator defined as:

    Code:
    				  
    { wpUsername : ? has text : 'User name must be entered (valang)' : 'error.fieldBlank'}
    { wpUsername : ? has no text or length(?) >= 3 : 'User name too short (valang)': 'error.tooShort'}

    This works beautifully. Now, I'm trying to move the actual error messages out of the Valang xml and into a properties file.

    Something like
    Code:
    error.fieldBlank={0} must be entered.
    error.tooShort={0} must be at least {1} characters long.
    And my JSP is

    Code:
     
    <form:errors path="wpUsername">
       <div class="errorMessage threefourthwidth">
          <spring:message code="error.fieldBlank"/>
       </div>
    </form:errors>
    Problem: <spring:message> requires the code attribute. However, there are two messages that could be bound for the username field, each with a different error message, and therefore a different error key.

    Is there an easy way to say "Display the error message for this field by looking it up from the properties file?"

    As an aside, how do you externalize error messages, while ensuring that you still have one relevant error per field.
Working...
X