Tuesday, June 22

Griffon Validation Plugin 0.4 Release

Just released GValidation plugin 0.4. In this post I would like to highlight some of enhancement and new feature introduced in this release.

1. @Validatable AST Transformation

In the previous version user can enhance regular Groovy class in their Griffon application manually using:


With 0.4 release now this manual process can be replace by the convenient @Validatable annotation thanks to Groovy AST transformation. Any class now annotated with @Validatable will be automatically synthesized with validation capability.

import net.sourceforge.gvalidation.annotation.Validatable

class AnnotatedModel {
String id
String email = " "

static constraints = {
id(nullable: false)
email(email: true)

Other than the fact that annotated class is enhanced during build-time instead of run-time as for the models and manually enhanced objects, they behave identically from user's point-of-view.

2. Bindable errors

In this release the dynamic errors field in models and Validatable objects has been enhanced to be Bindable, hence standard SwingBuilder binding can be utilized to tie errors automatically to a component. This is particularly handy when building error notification component to display error message for the user. For example with this new capability now you can simple bind the error to the build-in ErrorMessagePanel without manually synchronizing it after each validation.

container(new ErrorMessagePanel(messageSource),
id: 'errorMessagePanel', constraints: NORTH,
errors: bind(source: model, 'errors'))

3. beforeValidation callback

Inspired by Rails before_validation callback, now GValidation provides a similar pre-validation callback to give model developer a chance to manipulate data right before validation. Here is an example how this kind of callback can be used:

class ServerModel {
@Bindable String serverName
@Bindable int port
@Bindable String stringForm

def beforeValidation = {
setStringForm "${serverName}:${port}"


For more information please check out the GValidation Wiki Page. As usual your feedback and comment are always welcome.

No comments: