views:

279

answers:

1

If I have a list object I know that I can bind class property fields to form using the code below.

<c:forEach items="${items}" var="i" varStatus="itemsRow">
   <input name="items[${itemsRow.index}].fieldName" type="text"/>
</c:forEach> <form:errors path="items" />

What do I do if the property is a Set object. I have read about initBinder in the Controller class but it does not work. Can anyone paste code here to accomplish this??

A: 

You need to use the checkbox control:

<form:form>
      <table>
          <tr>
              <td>Interests:</td>
              <td>
                  <%-- Approach 2: Property is of an array or of type java.util.Collection --%>
                  Quidditch: <form:checkbox path="preferences.interests" value="Quidditch"/>
                  Herbology: <form:checkbox path="preferences.interests" value="Herbology"/>
                  Defence Against the Dark Arts: <form:checkbox path="preferences.interests"
                      value="Defence Against the Dark Arts"/>
              </td>
          </tr>
      </table>
  </form:form>

See more at the documentation

David Rabinowitz
The Set object is Set<ProductImages> and will need to show text fields so that image name can be modified etc...The above approach is for checkboxes not input text fields, can someone paste some code on how to use initbinder.I thhink this problem can be solved using initBinder method in the Controller class