The fact is that struts will not handle unchecked checkbox.I got a problem.Set the bean type is InfoForm and the recommend field is associated with a checkbox. In a Controller A ,set the recommend field with a value 1,means that the checkbox should be checked when load the page. After load the page ,i click the checkbox and set the checkbox to be unchecked. Next,i submit the form to a method in a Controller.But the recommend field value will be 1 because the struts checked the checkbox was unchecked status,then will do nothing with it ,and the recommend field value passed back to the back end.How can i deal with it?
Asked
Active
Viewed 967 times
1
-
Like this: http://stackoverflow.com/a/21827853/1654265 – Andrea Ligios Nov 04 '16 at 15:46
-
is not true, see http://stackoverflow.com/a/37045579/573032 – Roman C Nov 10 '16 at 12:07
1 Answers
0
I solved it as this:
<script>
$(function () {
$('.ckbox').each(function () {
var next = $(this).next('input[type="hidden"]');
if (next.val() == 1)
this.checked = true;
else
this.checked = false;
})
$(".ckbox").bind('change', function () {
var next = $(this).next('input[type="hidden"]');
if (this.checked == true)
next.val(1);
else
next.val(0);
})
});
</script>
<input type="checkbox" class="ckbox"/>recommend
<input type="hidden" name="infoBeanForm.recommend" value="${(infoBeanForm.recommend)!0}"/>
<input type="checkbox" class="ckbox"/>
<input type="hidden" name="infoBeanForm.clientType" value="${infoBeanForm.clientType[0]!0}"/>
android
<input type="checkbox" class="ckbox"/>
<input type="hidden" name="infoBeanForm.clientType" value="${infoBeanForm.clientType[1]!0}"/>
ios
kinglao
- 151
- 9