API / Apache Grails Interview questions
What is a Grails command object?
A command object is a plain Groovy class used to bind and validate incoming request data for a controller action, separate from any GORM domain class, which is useful whenever the shape of the data a form submits doesn't map cleanly onto a persisted entity.
It gets its own constraints block just like a domain class does, so Grails' standard validation and error-reporting machinery applies identically, but because it isn't a domain class, saving it doesn't touch the database at all — it's purely a typed, validated container for incoming data. A controller action simply declares a parameter of the command object's type, and Grails automatically binds matching request parameters into it and runs its validation before the action body even executes.
A classic use case is a multi-step registration wizard, a search form spanning several unrelated domain classes, or a login form — none of these map one-to-one onto a single persisted entity, but all benefit from the same declarative validation and clean parameter binding a domain class would get, without forcing an artificial domain class into existence just to hold form data.
More Related questions...