Checkbox values can not be unset
I may be asking the wrong questions here.
This is a jsp project that I am m开发者_运维技巧aking small change to. I added a new checkbox to the page. Saving the form with the checkbox checked seems to be working as expected; however, if the box is unchecked and the form is submitted for saving, it seems to be ignoring the checkbox -- it stays checked upon refresh.
I use firebug and find that the submitted form content indeed does not contain "mycheckbox=" pair.
The business object seems to be automatically constructed by Spring, and its values are automatically filled in, so I don't know where I can intercept the flow and consider the lack of "mycheckbox" as an uncheck.
Any pointers?
edit: i believe webflow is also used in this project.
edit2: I violated inter-galatic law to get it to work, by using a string in code and varchar(1) in the DB, with 'Y' to indicate true, and 'N' to indicate false.
You have two choices :
1: you use Spring tag :
<form:checkbox path="check_name" checked="true" />
2: you use html
<input type="checkbox" name="check_name" id="check_name" checked="true" />
<input type="hidden" name="_check_name" value="on" />
With the second choice, Spring will use the _check_name to set the value.
精彩评论