Grails: How to combine domain objects' errors with command objects' errors?

假如想象 提交于 2019-12-03 02:16:49

I think the full answer is:

if (!user.validate() || !user.save(true))
{
    if (user.errors.hasErrors())
    {
        user.errors.allErrors.each {FieldError error ->
            final String field = error.field?.replace('profile.', '')
            final String code = "registrationCommand.$field.$error.code"
            command.errors.rejectValue(field, code)
        }
    }
    chain(action: 'registration', model: [command: command])
    return
}
Karthick AK

I did the following for my project and found it to be more cleaner!

domain.errors.each {
  cmdObject.errors.reject(it.code, g.message(error: it))
} 
Tomas Lin

You could probably use the reject mechanism, i.e.

domainObjects.errors.each{
     commandObject.errors.reject( ... )
}

http://grails.org/doc/1.3.7/ref/Domain%20Classes/errors.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!