In my Spring application, I have jsp that has a form where I want to have multiple submit buttons that go to the same controller. I need to determine which button was pressed in the controller. The form displays several elements to the user, and they can select one of the elements, with the only difference being the identifier of the selected element.
In jsp, I create the form as follows:
<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 the message "Data binding errors: 1" in the log, and the form is not submitted to the controller.
I tried changing myCommand.id from int to String, but then the value when it was sent is id1, id2, id3 ... (all identifiers in a comma-separated list) without the ability to determine which button was pressed. I do not want to specify different actions for each button, as the number of elements can grow, and the action is the same for them, just with a different identifier.
How can I use several buttons in this form and get the value in the controller?
source share