0

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>

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

if i use form:checkboxes then how do i arrange them on the page? in certain divs/spans?
If you need to do so then you should use <c:forEach /> to loop the items and in the loop you can create individual <form:checkbox /> in whatever div/span you need to put it in.
currently to get the checkbox list i use a scriptlet :P like <%=getLocationCheckboxes()%>, can i use <form:checkbox..> inplace of <input type="checkbox"..> there (in the function getLocationCheckboxList()?
No. Its a bad thing to use scriptlet in the jsp. You should call this method right from your controller and then put this list in the modelmap object and then on the jsp render the list of checkboxes using the list passed.
yeah probably i should do that :( thnks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.