0

我的代码有问题。我如何处理从服务到我的 gsp 的错误?我尝试使用服务或控制器的渲染,在调用 save() 期间发生验证错误: - 字段“core.db_email”上的对象“talent.CandidateProfile”中的字段错误:拒绝值 [];具有完整异常跟踪的代码。我的消息来源:

 def create() {
        [candidateProfileInstance: new CandidateProfile(params)]
    }

    def save() {
        def candidateProfileInstance = new CandidateProfile(params)
        if (!candidateProfileInstance.save(flush: true)) {
            render(view: "create", model: [candidateProfileInstance: candidateProfileInstance])
            return
        }

        flash.message = message(code: 'default.created.message', args: [message(code: 'candidateProfile.label', default: 'CandidateProfile'), candidateProfileInstance.id])
        redirect(action: "show", id: candidateProfileInstance.id)
    }

我的 .gsp 页面代码

<div class="full-filed">
            <h3>Email Address:</h3>
        </div>
        <div    class="fieldcontain ${hasErrors(bean: candidateProfileInstance, field: 'core.db_email', 'error')} ">
            <label for="core.db_email" class="error_message"> <g:message
                    code="candidateProfile.core.db_email.label" default="Dbemail" />
            </label>
        </div>
        <g:textField name="core.db_email" value="" class="loginTxtBox" placeholder="Email Address" />

我只想向用户显示一个错误,而不是完整的异常跟踪

4

1 回答 1

0

形成你的 config.grooyPage

//grails.gorm.failOnError = true

只需评论这一行......所以它会显示您的自定义错误

于 2013-05-21T05:46:09.167 回答