My first proper Grails contribution
I’m rather pleased to have been able to contribute a new feature to Grails. It’s my first significant contribution to the Grails codebase. Grails, for those who don’t know, is a Groovy application framework using coding by convention in a similar vein to Rails. You write minimal code and almost no configuration, and get solid webapps out the other end. The ORM/Hibernate integration is just amazing.
The new feature adds custom validation support to domain class constraints. You can supply a closure to do any validation you like, with full control of the message code used when failures occur. What’s more this works in tandem with other constraints such as nullable, blank, minLength etc.
This is but part of the journey for validation. We plan some nice convention based validator lookup so you can easily extend the base set of named validators in you application, and providing constraint validation on non-domain classes.
The interesting part for me is coding Java to talk to Groovy closures and the issues that raises. It makes me appreciate the hoops the Java end has to jump through to make the convention thing work by providing flexibility in usage, and also the nuances of type compatibility differences between Groovy and Java.
It just makes me wish more of Grails was actually written in Groovy… if it weren’t for the performance impact of that. Writing Java these days is getting to be a bit of a bore compared to writing Groovy.




















