문제

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