Skip to content

Instantly share code, notes, and snippets.

@glfruit
Last active December 22, 2015 03:19
Show Gist options
  • Save glfruit/6409336 to your computer and use it in GitHub Desktop.
Save glfruit/6409336 to your computer and use it in GitHub Desktop.
Friendly Error Messages for Grails
class Bootstrap {
def grailsApplication
def messageSource
def init = { servletContext ->
for(dc in grailsApplication.domainClasses) {
dc.metaClass.getErrorStrings = { Locale locale = Locale.getDefault() ->
def stringsByField = [:].withDefault { [] }
for(fieldErrors in delegate.errors) {
for(error in fieldErrors.allErrors) {
String message = messageSource.getMessage(error,locale)
stringsByField[error.field] << message
}
}
stringsByField
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment