class Book {
String title
Author author
static constraints = {
title blank: false, size: 5..150
author nullable: true
}
}
constraints
Purpose
Allows the definition of declarative validation constraints. See validation in the user guide.
Examples
Description
Constraints are defined using the declarative constraints DSL as described in the validation section of the user guide. Once evaluated, validation can be applied through the use of the validate method:
def b = new Book()
assert !b.validate()
The static constrainedProperties
property is a Map such that the keys in the Map are property names and the values associated with the keys are instances of ConstrainedProperty:
def constraintsMap = Book.constrainedProperties
for(entry in constraintsMap) {
// propertyName is a String
def propertyName = entry.key
// constrainedProperty is a ConstrainedProperty
def constrainedProperty = entry.value
// ...
}