0

私はこの設定をしていますが、検証が機能していません

インデックス.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 ={}
4

1 に答える 1

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>

GrailshasErrorsドキュメント

そして、以下を使用して検証に合格したかどうかをコントローラーにチェックインします(アクションを保存します)。

    if (!yourBean.save(flush: true)) {
        render(view: "create", model: [yourBean: yourBean])
        return
    }
于 2012-12-09T14:42:51.680 に答える