Reputation: 38106
I have a command object in another package from my controller. I import it in the controller. I create and return an instance of this command from the create action:
def create = {
def reportCreateCommand = new ReportCreateCommand()
reportCreateCommand.name = params.name
reportCreateCommand.jrxmlFile = params.jrxmlFile
return [cmd: reportCreateCommand]
}
But the save action closure doesn't instantiate an object of this command from the properties:
def save = { ReportCreateCommand cmd ->
if (cmd.validate()){
def reportInstance = cmd.createReport()
reportInstance.save()
redirect(action:"show", id:reportInstance.id)
}
else {
render(view:"create", model:[cmd:cmd])
}
}
Apparently cmd is null in the save closure. The command class has two properties name and jrxmlFile. From what I know grails should instantiate the command object in the save method from the params. Do I have to do anything else?
Upvotes: 1
Views: 622
Reputation: 517
Yes, there is no validate() method on command objects. Just call hasErrors as suggestd by Aaron
Upvotes: 0
Reputation: 33335
I believe calling cmd.validate()
is unnecessary, you should just call cmd.hasErrors()
. The command object will be validating by default on creation of the object
Upvotes: 2