Grails checkbox simple question
I have this checkBox in my view inside a fo开发者_高级运维rm:
<g:checkBox name="myCheckbox" value="${false}" />
In my controller, I how do I know if it is checked or not?
I tried:
if(!params.myCheckbox)
// obviously not, because it will always be true
if(params.myCheckBox.checked)
// also dont work.
if (params.myCheckbox) {
println "checkbox is checked"
} else {
println "checkbox is not checked or myCheckbox parameter is missing"
}
If you need to separately handle "checkbox is not checked" and "myCheckbox parameter is missing", use:
if (params.myCheckBox == null) {
println "myCheckbox parameter is missing"
} else if (params.myCheckbox) {
println "checkbox is checked"
} else {
println "checkbox is not checked"
}
精彩评论