Results 1 to 2 of 2

Thread: annotation-based bean validation error messages

  1. #1
    Join Date
    Oct 2006
    Posts
    156

    Default annotation-based bean validation error messages

    Hi,

    I'm investigating an annotation-based approach to command bean validation using spring modules. In the tutorial, the following command bean (getters and setters omitted) is used:

    Code:
    public final class UserMessage {  
           
      @NotBlank  
      @Length(max = 80)  
      private String name;  
           
      @NotBlank  
      @Email  
      @Length(max = 80)  
      private String email;  
           
      @NotBlank  
      @Length(max = 4000)  
      private String text;  
    }
    And the following are (some of the) configured error messages:

    Code:
    UserMessage.email[not.blank]=Please enter your e-mail address.  
    UserMessage.email[email]=Please enter a valid e-mail address.  
    UserMessage.email[length]=Please enter no more than {2} characters.
    The net effect is that if the rule about e-mail length is not observed, the message produced is:

    "Please enter no more than 80 characters"

    Where are the values substituted for each of the {} placeholders documented? In other words, how can I find out what will be substituted for {0}, {1},...,{N} for a particular validation rule?

    Thanks in advance,
    DM
    Last edited by domurtag; Jul 30th, 2008 at 07:11 PM.

  2. #2
    Join Date
    Jan 2007
    Location
    Orlando, FL USA
    Posts
    84

    Default

    Hello domurtag,

    Those placeholder are filled when you create Error instances using one of the reject methods that has "errorArgs"

    Eg see http://static.springframework.org/sp....lang.O bject[],%20java.lang.String)

    -Z
    http://www.jroller.com/thebugslayer - notes on java, scala and other development stuff.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •