Handling validation on Entity properties

Grails GORM (Grails Object Relational Mapping) allows you to define a number of validation rules that are carried through to your view when entering data.

For example with following simple Entity:

class Test1 { 
    Long id
    Long version
    String string1
    Long testLong
    Float float1
    def constraints = {

The ‘constraints’ section defines the rules on the properties on this Entity – the rules are a comma separated list of name/value pairs for the rules to be applied. Notice the ‘blank’ only works on String properties. To require a value for any other property type, use ‘nullable:false’.

Here are some further self-explanatory examples from the online Grails docs:


   def constraints = {
          age(min:new Date(),nullable:false)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.