knocker_d
knocker_d

Reputation: 566

grails : how to validate single field in command object

I want to manually validate field in command object

I know I can get field's max value (and min) with this:

MyDomain.constraints.myField.getAppliedConstraint('max').maxValue

How can I execute 'validate' command on 'myField' and get errors object ?

Upvotes: 5

Views: 2734

Answers (1)

aiolos
aiolos

Reputation: 4697

Have a look at the grails docs.

You could use the validate() method on a defined list of properties:

if(!yourObject.validate(['myField'])) {
    yourObject.errors.each { 
        println it
    }
}

Upvotes: 11

Related Questions