Created
December 27, 2012 14:50
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyDomain { | |
... | |
static constraints = { | |
items(validator: requiresAtleastOne) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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