Does anybody know how I could get the fieldError
to print out in the example below.
for each item with an error, I would like to print custom error messages
You need access to the messageSource bean, e.g. with
def messageSource
in your controller or service. Then you can access the messages with
def locale = Locale.getDefault()
for (fieldErrors in bean.errors) {
for (error in fieldErrors.allErrors) {
String message = messageSource.getMessage(error, locale)
}
}