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

前端 未结 3 729
日久生厌
日久生厌 2021-02-05 17:06

Suppose I have User domain class and RegistrationCommand class. So when user is registering on website there are two steps for data validation:

  1. RegistrationCommand
3条回答
  •  情深已故
    2021-02-05 17:43

    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
    }
    

提交回复
热议问题