Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

parameterized Grails validation messages

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}

like image 413
Dónal Avatar asked Jul 13 '09 23:07

Dónal


1 Answers

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.
like image 164
Dónal Avatar answered Sep 25 '22 01:09

Dónal