[英]grails g:field error not showing
我有此設置,但是驗證不起作用
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 ={}
您需要在表單中使用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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.