hasErrors
目的 Purpose
Checks whether a bean, request scope, or model reference has any errors and if so invokes the body of the tag. Typically used in conjunction with either eachError or renderErrors使用例 Examples
Checks whether there are any errors for any bean throughout the request scope:<g:hasErrors> <g:eachError><p>${it.defaultMessage}</p></g:eachError> </g:hasErrors>
<g:hasErrors bean="${book}"> <g:eachError><p>${it.defaultMessage}</p></g:eachError> </g:hasErrors>
<g:hasErrors bean="${book}" field="title"> <div class="errors"> <g:renderErrors bean="${book}" field="title" as="list" /> </div> </g:hasErrors>
<div class="prop ${hasErrors(bean:user,field:'login', 'errors')}"> <label for="login"><input type="text" name="login" /> </div>
errors
CSS class.Checking for errors inside a nested object:<div class="prop ${hasErrors(bean:parent, field:'child.name', 'errors')}"> <label for="child.name" /> <input type="text" name="child.name" value="${fieldValue(bean: parent, field: 'child.name'} /> </div>
詳細 Description
属性 Attributes
bean
(optional) - The bean to check for errorsmodel
(optional) - The name of the model reference to check for errorsfield
(optional) - Check if a field of the bean or model reference has errors