Grails 1.1 beta3 Is Out! Thursday, January 29, 2009

We are closing in on the much anticipated release of Grails 1.1. Today beta 3 was released. See the release notes.

A new feature that has not been documented yet involves new validation capabilities. Up to this point, domain classes and command objects within a Grails app have supported really powerful validation capabilities. See section 7 in The User Guide for info on how that works. What is new is now you can apply those same validation capabilities to any class within a Grails app, not just domain classes and command objects. Making a class validateable involves defining a static property called "constraints" and assigning a closure, just like you would in a domain class or a command object.

Second, you have to tell Grails about your validateable class. You have 2 options for doing that. One option is to mark you class with the org.codehaus.groovy.grails.validation.Validateable annotation. Another option is to define your validateable classes in grails-app/conf/Config.groovy by assigning a value to the grails.validateable.classes property. That would look something like this...

grails.validateable.classes = [ com.mycompany.dto.SomeClass, com.mycompany.SomeOtherClass]

An annotated class might look something like this...

// src/groovy/com/companyname/SomeClass.groovy
package com.companyname

import org.codehaus.groovy.grails.validation.Validateable

class SomeClass {
Integer age
String name

static constraints = {
age range: 16..66
name blank: false, size: 5..35

Note that if you are using the annotation based approach, Grails will search all classes in the app to find all of the @Validateables. While that isn't really a performance problem, you can tune that a bit by specifying some specific packages that Grails should search. To do that, assign a value to grails.validateable.packages in grails-app/conf/Config.groovy like this...

grails.validateable.packages = ['com.companyname.dto', 'com.companyname.someotherpackage']

If the grails.validateable.packages property has a value then Grails will only look in those packages (and packages below those packages) for classes marked with @Validateable.

While this is still beta software, I think the feature will end up being delivered in the final release pretty much like it is described above. If you have any input on that or any other features in Grails. We would love to hear from you. Bring it to the mailing list or file a JIRA issue.



Donny said...

Thanks for showing us how to use the new validation feature!!!

superflav said...

Jeff, is domain-style data binding possible in clases marked @Validateable? I'm hoping the answer's yes as I've got a scenario where I'd like to take a map of strings, bind them to a non-domain/non-command object instance and then enact validation.

Great stuff!

Chris Fraser

Jeff Brown said...


No. Data binding is separate from validation. Adding data binding support to classes could be done, but isn't supported at the moment.

I am wondering where your map of data is coming from. If the data is coming as request params, then a command object would give you data binding and validation capabilities.

superflav said...

Jeff, I'd like to bind to collection fields within a command object like Rob's doing here: , but I'd like those collection fields to be richer data types than he's using.

I tried instantiating references to another command object in Grails 1.0.4, but that didn't work. I'm hoping that this issue is fixed in Grails 1.1 with , but if not I was thinking that your @Validateable solution might just do the trick.



superflav said...

Jeff, is this feature for *any* Java POJO, or just Groovy-based ones?

Anonymous said...

Any new posts or has this blog moved?

Jeff Brown said...

Nope, the blog hasn't moved. I have just been neglecting it pretty badly.

However, a post is coming soon. :)

Jeff Brown said...


For data binding, of course the bindData method is available (and has been for some time)

Anonymous said...

酒店打工 酒店兼職
台北酒店 打工兼差 酒店工作
酒店經紀 禮服店
酒店兼差 酒店上班 酒店PT 酒店酒店喝酒 酒店消費 喝花酒 粉味

cc22 said...




Cheap Viagra said...

Greetings Jeff Brown and readers!
I have been researching on the net in order to find some affairs which are surely going to help me n my way to finish a High School proyect. Anyway, What I meant is that this column made my day.

Andrew Jorge said...

I'd like to get a map of sequences, bind them to a non-domain/non-command objected example and then enact validation.
help with thesis

malini ecorp said... provides ASP.NET in hyderabad with best faculties on real time projects. We give the best online trainingamong the ASP.NET in Hyderabad. Classroom Training in Hyderabad India

Naviya Nair said...

Interesting Article

Java Online Training from India | Core Java Training Online

Java Online Training | Java EE Online Training

oracle classroom training said...

This listing is certainly very beneficial.This is the right weblog. it's far very interesting weblog Ever. Thanks for giving one of these brilliant article.

for more information please check the site
oracle cloud fusion financials “>

oracle procurement said...

It is nice blog.Very interesting blog this is.

oracle fusion SCM on line training

oracleR12 said...

You have posted Very good information to all readers .surely i am very much interested in reading this type of articles and develop my skills .keep posting more articles.
thank you.
oracle EBS training