Reputation: 3885
I have a problem with automatic data binding of boolean which is in embedded class. I created an example for this:
Domain Class:
class TestMe {
TestEmbedded testEmbedded = new TestEmbedded()
static embedded = ['testEmbedded']
static constraints = {
}
}
Embedded Class:
class TestEmbedded {
String stringEmbedded = "test"
Boolean booleanEmbedded = false
}
Controller:
class TestMeController {
static scaffold = true
}
Scaffolded edit and creat renders inputs properly. When I create or edit an instant, embedded properties work fine. There is only one issue. When I try to edit a TestMe.testEmbedded.booleanEmbedded from true value to false value (using checkbox) (other way round edit works!), the data binding doesn't work. Is it a bug of grails? Is there any good workround?
Upvotes: 3
Views: 850
Reputation: 3885
I've created a Grails Issue for this because it seems to be a bug of Grails.
http://jira.grails.org/browse/GRAILS-9664
Upvotes: 0
Reputation: 3709
Make sure the field is actually being passed when set to false by printing the params in the controller. You'll have to create a dummy update method in the controller to test this:
class TestController {
static scaffold = true
def update() {
params.each {
printing it
}
}
}
Standard HTML forms don't send unchecked checkboxes; Grails creates a hidden variable (which is always sent) with an underscore in front of the checkbox name to handle this if you are using g:checkBox
If the form isn't using the g:checkBox
you can either create the hidden variable manually or handle it with logic in the controller. Viewing the source of the generated page could be helpful.
Hopefully this helps!
Upvotes: 0