tags:

views:

33

answers:

2

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?

+1  A: 

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

Aaron Saunders
A: 

Yes, there is no validate() method on command objects. Just call hasErrors as suggestd by Aaron

Marc Palmer