Announcement Announcement Module
Collapse
No announcement yet.
Binding a form checkbox to an ArrayList: First element is a superfluous emtpy element Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Binding a form checkbox to an ArrayList: First element is a superfluous emtpy element

    Hello,

    I am trying to bind a set of form checkboxes to an ArrayList<Integer> named "ids" like this

    Code:
    <form:form commandName="ids">
    
      <c:forEach var="object" items="${objects}">
         <form:checkbox path="ids" value="$object.id}" />
          <!-- some other code -->
      </c:forEach>
    
    </form:form>
    After submitting, "ids" does contain the ids of the selected items, but the first element of the ArrayList is an empty element pointing to "null". The correct items are added afterwards. When no element is selected, an empty ArrayList is (correctly) returned.
    Amongst other things, this confuses the ids.size() method when I want to display the number of selected items on another page of my application. It is fairly easy, but ugly to work around, and I am simply curious why this would be the case

    Does anybody have an idea why this is happening? I am using Spring 3.1.0 and webflow 2.3.0.

    Thanks, Ellen
    Last edited by Ellen König; Jan 12th, 2012, 04:20 AM.
Working...
X