Grails has very good support for binding request parameters to a domain object and it\'s associations. This largely relies on detecting request parameters that end with
I've faced the same problem with nested command objects, so I did the following workaround:
To illustrate, here is a sample pseudo code:
class CommandObjectBig{
String name
CommandObjectSmall details
static constraints = {
name (blank: false)
}
}
class CommandObjectSmall{
String address
static constraints = {
address (blank: false)
}
}
In the controller:
.
.
.
def save = { CommandObjectBig cob, CommandObjectSmall cos ->
//assuming cob is bounded successfully by grails, and we only need to handle cos
bindData(cos, params.details)
cos.validate()
//then do you code logic depending on if cos or cob has errors
if(cob.hasErrors() || cos.hasErrors())
render(view: "create", model: [bigInstance: cob, smallInstance: cos])
}
else
{
//create the Domain object using your wrapper command object, and assign its details
//property it's value using cos command object instance, and call the save on you
//command object and every thing should go smoothly from there
.
.
.
}
.
.
.