Suppose I've User domain class and RegistrationCommand class. Then when user is signing up on website you will find two steps for data validation:

  1. RegistrationCommand constraints validation.
  2. User domain object constrains validation.

Controller action receive command object and pass it to see inside a model after computing. So, I wish to join domain objects' validation errors with command objects' errors and pass them as part of command object. What's the easiest method to do this?

You can most likely make use of the reject mechanism, i.e.


I believe the entire response is:

if (!user.validate() || !
    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])