如何在Grails中显示异常?

时间:2013-05-21 05:32:23

标签: grails grails-2.0 grails-controller grails-validation

我的代码有问题。如何处理从服务到我的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" />

我想向用户显示错误,但不是完整的异常跟踪

1 个答案:

答案 0 :(得分:0)

形成你的config.grooyPage

// grails.gorm.failOnError = true

只需对此行发表评论......这样就会显示自定义错误

相关问题