1

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?

Roman C
  • 49,761
  • 33
  • 66
  • 176
kinglao
  • 151
  • 9

1 Answers1

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
&nbsp;&nbsp;&nbsp;
<input type="checkbox" class="ckbox"/>
<input type="hidden" name="infoBeanForm.clientType" value="${infoBeanForm.clientType[1]!0}"/>
ios
kinglao
  • 151
  • 9