我的代码有问题。如何处理从服务到gsp的错误?我尝试了从服务或控制器渲染,在调用save()时发生验证错误:-对象的天赋字段错误。字段'core.db_email':拒绝值[];具有完整异常跟踪的代码。我的消息来源:
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" />
我只是想显示给用户一个错误,但不是完整的异常跟踪
form your config.grooyPage
//grails.gorm。failOnError = true
注释到这行…它会显示你的自定义错误