In my Spring application, I have a jsp that has a form where I want to have multiple submit buttons that go to the same controller. I need to be able to determine which button was pressed in the controller. The form displays a number of items to the user and they can select one of the items with the only difference being the ID of the selected item.
In the jsp, I'm creating the form like this:
<form:form method="post" commandName="myCommand">
<c:forEach items="${model.availableitems}" var="item">
<span class="item">${item.description}</span>
<input type="hidden" name="id" value="${item.ID}"/>
<input type="submit" name="SelectButton" value="Select" />
</c:forEach>
</div>
</form:form>
However, this gives me a "Data binding errors: 1" message in the log and the form isn't submitted to the controller.
I tried changing the myCommand.id from an int to a String, but then the value when it's submitted is id1,id2, id3... (all of the IDs in a comma delimited list) with no way of determining which button was pressed. I don't want to have to specify different actions for each button as the number of items can grow, and the action for them is all the same, just with a different ID.
How can I have multiple buttons in this form and get the value in the controller?