Spring MVC HTML checkbox not checked when form returns from onSubmit

I'm using the SimpleFormController and have checkboxes in the view. When the form is submitted the values of the checkboxes are correctly binded to the bean. But when the form (jsp view) returns from the onSubmit method the checkboxes are not checked. I've tried doing the following things : -

  1. <input name="location" description="xyz" type="checkbox" id="location-filter-1" style="float:left" value="1"/>

  2. <input name="location" description="xyz" type="checkbox" id="location-filter-1" style="float:left" value="1"/> <input type="hidden" name="_location" value="visible"/>

  3. <springbind:bind path="location"> <input name="location" description="chennai" type="checkbox" id="location-filter-1" style="float:left" value="1"/> <input type="hidden" name="_location" value="visible"/> </springbind:bind>

I've had no luck in getting thoses checkboxes checked. Could any one suggest a work around for this. In the bean, an Integer array is used to hold the values for checked checkboxes :- private Integer[] location;

The checkboxes are currently like this:- the checkboxes are arranged like this

<ul>
    <li class="x">
     <span>text</span>
     <input type="checkbox" value="1" id="location-1" name="location"/>
    </li>
    <li><span>text</span>
     <input type="checkbox" value="2" id="location-2" name="location"/>
     </li>
     <li>...</li>
      ..
</ul>

Answers


You should try using form tag library of spring framework to bind the values of your checkboxes.

<form:checkboxes items="" path=""/>

In items attribute pass the list that holds the checkbox values and in path use location.

Hope this helps you. Cheers.


Need Your Help

Accessing NSString within NSMutableArray

ios objective-c nsstring nsmutablearray

Why can I not access the 4th element of an NSMutableArray when I initialise with a NSString object rather than input the text manually?