views:

418

answers:

2

Hi,

In the messages.properties file in a Grails application I've seen examples of validation messages such as:

User.password.size=Size of bar must be between {0} and {1}

which applies to

class User {

    String password
    static constraints = {
        password(size:5..15)
    }
}

This example assumes that {0} is bound to the minimum size and {1} is bound to the maximum size, but I cannot find any documentation of which parameters may be used by error messages for each built-in constraint. In other words, what I'd like to know is: for each built-in constraint what is the meaning of {0}....{n}

Thanks, Don

A: 

You're right, I've never found any documentation of that either. Best bet? Change your messages to something like:

User.password.size=0:{0}, 1:{1}, 2:{2}, etc...

and see what you get for each one you're interested in. If you posted that info to the Nabble message board on Grails, I'm sure it would find it's way into the documentation.

Good luck.

Bill James
+1  A: 

I did some experimentation and I discovered that for a constraint such as:

class User {    
    String password
    static constraints = {
        password(size:5..15)
    }
}

The values of the placeholders are:

 0. Name of the class (User)
 1. Name of the property (password)
 2. Value of the property
 3. First constraint parameter (5)
 4. Second constraint parameter (15)
 5. etc.
Don