Announcement Announcement Module
No announcement yet.
MessageSource and Errors argument Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • MessageSource and Errors argument

    I struggle with translating messages via the MessageSource and I cannot figure out how to use the "argument" feature.

    I create an Errors by
    errors.rejectValue(lastname, "error.between", new Object[] {"5", "10"}, "myDefaultMessage");
    error.between=must be between {0} to {1} characters long.

    Expected result on the webpage:
    must be between 5 to 10 characters long.
    Actual result on the webpage:
    must be between {0} to {1} characters long.

    While debugging I can see that the Errors object looks allright, with the errors argument and all, but when the debug session enters the MessageSource.getMessage() (class eSource) the arguments are no longer there...

    I have search through the forum but all I can find is how to do this in the JSP page (and it works), but since MessageSource.getMessage() takes an Object array as argument to supply this substitution functionality via the java.text.MessageFormat class I cannot see why I need to do it in the JSP.

    I read Cowboy bob's post about overriding onBindAndValidate() and the suggestion found here:
    but that is not really what I'm looking for since the arguments are supplied via the Bean Validation Framework:
    <property name="lastname">
    	<not-blank code="error.nonempty"/>
    	<length min="5" max="10" code="error.between" args="5,10"/>
    Since this functionality obviously IS there (in MessageSource.getMessage(), in bean validation framework and Errors containing an Argument member) I guess I just don't know how to use it...

  • #2
    ...never ask questions when you have been working for 10 hours: go home! :-)

    After a good nights sleep I realised it definetly was me not knowing how to use the arguments feature. Anyone else wondering about it, this is how I use it (from the JSP):
    <spring:message code="${error.code}" text="${error.defaultMessage}"  arguments="${error.arguments}"/>