我有此设置,但验证无效
index.gsp中:
<g:form name="loginForm" autocomplete="off" controller="company" action ="save">
<table >
<tr>
<td><g:field type="text" name="company" required="true" value="${c?.companyName}" /></td>
</tr>
</table>
控制器:
def index = {
def c =new Company()
//c=params
return [c:c]
}
def save ={}
答案 0 :(得分:0)
您需要使用表单中的hasErrors
方法检查错误:
<div class="fieldcontain ${hasErrors(bean: yourBean, field: 'yourField', 'error')} required">
<label for="yourField">
<g:message code="yourBean.yourField.label" default="yourField" />
<span class="required-indicator">*</span>
</label>
<g:textField name="content" required="" value="${yourBean?.yourField}"/>
</div>
Grails hasErrors文件。
如果验证已通过,请检查您的控制器(保存操作):
if (!yourBean.save(flush: true)) {
render(view: "create", model: [yourBean: yourBean])
return
}