Grails: how to validate a single field in a command object

I want to manually check a field in a command object

I know that I can get the maximum value of the field (and min) with this:

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

How can I execute the 'validate' command on 'myField' and get an error object?

+4
source share
1 answer

Check out the grails docs .

You can use the validate() method for a specific list of properties:

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

All Articles