eachError
Purpose
Loops through each error of the specified bean or model. If no arguments are specified it will go through all model attributes and check for errors.
Examples
Loop through each error in the "book" bean:<g:eachError bean="${book}">
<li>${it}</li>
</g:eachError>
Loop through each error in the title field of the "book" bean:<g:eachError bean="${book}" field="title">
<li>${it}</li>
</g:eachError>
Loop through each error in model:<g:eachError model="${[book1:book1,book2:book2]}" field="title">
<li>${it}</li>
</g:eachError>
Loop through each error displaying its i18n message:<g:eachError bean="${book}">
<li><g:message error="${it}"/></li>
</g:eachError>
Description
Attributes
bean
(optional) - The instance of the bean to check for errors
model
(optional) - The name of model, an map instance, to check for errors
field
(optional) - The field within the bean or model to check for errors for
Source
Show Source
def eachError = { attrs, body ->
def errorsList = extractErrors(attrs)
def var = attrs.var
def field = attrs['field'] def errorList = []
errorsList.each { errors ->
if(field) {
if(errors.hasFieldErrors(field)) {
errorList += errors.getFieldErrors(field)
}
} else {
errorList += errors.allErrors
}
} errorList.each { error ->
if(var) {
out << body([(var):error])
} else {
out << body(error)
}
}
}