Skip to content

Instantly share code, notes, and snippets.

@cdeszaq
Created December 27, 2012 14:50
Show Gist options
  • Save cdeszaq/4388869 to your computer and use it in GitHub Desktop.
Save cdeszaq/4388869 to your computer and use it in GitHub Desktop.
Example of how to DRY up complex Grails validation logic and share it across different domain objects.
class MyDomain {
...
static constraints = {
items(validator: requiresAtleastOne)
}
}
class Validators {
static final confirmPasswordValidator = { value, command ->
if (command.password != command.confirmPassword) {
return 'command.confirmPassword.error.mismatch'
}
}
static def requiresAtleastOne = {val, obj->
if(!val?.size()){
return "default.requires.atleast.one"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment