This is probably a ridiculously easy question, but I've been struggling with it nonetheless.

I have a form:

.
.
.
<g:form controller='somecontroller' action='someaction'>
    <g:textField name='name'/>
    <g:checkBox name='active'/>
    <g:submitButton name='save'/>
</g:form>
.
.
.

And I have a command object:

class MyCommandObject{

    String name
    Boolean active

    static constraints{
        .
        .
        .
    }
}

When I try to access the active property of the command object in my controller, it's always false. The name property, however, is being properly populated. I've tried changing the value to true, and also ${true} (as I saw in some example) and none seem to work. What am I doing wrong here?

Edit: How I'm binding to the command object in the controller:

class MyController{

    .
    .
    .

    def save(MyCommandObject cmd){

        // Do validation/error checking

        def myDomainObject = new DomainObject()

        myDomainObject.name = cmd.name
        myDomainObject.active = cmd.active

        // Do something with myDomainObject

    }

}

I've also tried the style:

def save = { MyCommandObject cmd ->

    .
    .
    .
}
有帮助吗?

解决方案

Everything you've done looks fine and I've verified as working in 1.3.7 and 2.0.4.

Please do a grails clean and try again.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top