Wysmedia.com

Icon

~ We make IT easy for you ~

Checkbox of chaos

Yesterday I got a headache problem with a checkbox. I wrote like this on GSP

1
2
3
4
5
6
<g:form action="save">
... table ... 
<g:checkBox name="myCheckbox" value="" />
... other element ... 
<input type='submit' value='Save'/>
</g:form>

did you know what the happened ? myCheckbox always returned empty or null value everytime I saved the form. I thought Grails has bug at first, I did check and create a checkbox using scaffold and I found that value=”" makes the null value everytime I saved the form
The solution was simple enough:

1
2
3
4
5
6
<g:form action="save">
... table ... 
<g:checkBox name="myCheckbox"/>
... other element ... 
<input type='submit' value='Save'/>
</g:form>

Just eliminate value=”" and it all solved. I learned that using value=”somethingHere” can be useful if we want to save a value into our database. I hope my tricks can save you from headache. Be aware of checkbox .. hahaha…