This page last changed on Feb 03, 2006 by [email protected].

Domain Class Validation

Example

class User {
   @Property Long id
   @Property Long version

   @Property String login
   @Property String password
   @Property constraints = {
          login(length:5..15,blank:false,unique:true)
          password(length:5..15,blank:false)
   }
}

Validation Constraint Reference

Name Description Example Error Codes
blank set to false if a string value cannot be blank
login(blank:false)
className.propertyName.blank
email set to true if a string value is an email address
contactEmail(email:true)
className.propertyName.email.invalid
inList constrains a value so that it must be contained within the given list
name(inList:["Joe", "Fred", "Bob"] )
className.propertyName.not.inList
length Uses a Groovy range to restrict the length of a string or array
login(length:5..15)
className.propertyName.length.toolong, className.propertyName.length.tooshort
min sets the minimum value of a class that implements java.lang.Comparable
age(min:new Date())
className.propertyName.min.notmet
minLength sets the minimum length of a string or array property
login(minLength:5)
className.propertyName.minLength.notmet
minSize sets the minimum size of a collection or number property
children(minSize:5)
className.propertyName.minSize.notmet
matches Applies a regular expression against a string value
login(matches:"[a-zA-Z]")
className.propertyName.matches.invalid
max sets the maximum value of a class that implements java.lang.Comparable
age(max:new Date())
className.propertyName.max.exceeded
maxLength sets the maximum length of a string or array property
login(maxLength:5)
className.propertyName.maxLength.exceeded
maxSize sets the maximum size of a collection or number property
children(maxSize:25)
className.propertyName.maxSize.exceeded
notEqual validates that a property is not equal to the specified value
login(notEqual:"Bob")
className.propertyName.notEual
nullable set to false if the property value cannot be null
age(nullable:false)
className.propertyName.nullable
range Uses a Groovy range to ensure that a property's value occurs within a specified range
age(range:minAge..maxAge)
className.propertyName.range.toosmall or className.propertyName.range.toobig
size Uses a Groovy range to restrict the size of a collection or number
children(size:5..15)
className.propertyName.size.toosmall or className.propertyName.size.toobig
unique set to true if the property must be unique (this is a persistent call and will query the database)
login(unique:true)
className.propertyName.not.unique
url set to true if a string value is a URL address
homePage(url:true)
className.propertyName.url.invalid
Document generated by Confluence on Mar 29, 2006 08:46