Saturday, January 16, 2010

A Note On Validation Non Domain classes

Validation non domain classes is a very cool grails feature, but when you use it, you should remember one thing: Invoking clearErrors method before re-validation, specially last validate invocation returns false.
A piece of script means a lot of things:
def u= new foxgem.test1.User1(name:'')
assert u.validate() == false
u.name='foxgem'
assert u.validate() == false
u.clearErrors()
assert u.validate() == true
Here, there is a blank constraint on name property of foxgem.test1.User1. But the note is not necessary to Domain Class, so the second assert statement in the script will failed when foxgem.test1.User1 is a domain class.
This is very confusing, I hope this will be imporved in the future of Grails.