1

I have started to look into command object as a means for validating a form that has no domain associated with it. On my research, i found out that a command object either can be declared in the same package as my controller or in the controller class itself.

However, all the examples that I have seen so far have a separate command object class bot not inside the controller.

Can anyone show me an example or code to define a command object inside my controller itself?

1 Answer 1

1

There's nothing special about command object classes. You can declare them as an inner class inside your controller like this:

class MyController {

    class ActionCommand {
        String paramName
    }

    def action(ActionCommand actionCommand) {
        render actionCommand.paramName
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Typically they're top-level classes but are in the same .groovy file as the controller that uses them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.