title: Have multiple submit buttons in a form and determine which was pressed in a controller
body: <p>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.</p>
  
  <p>In the jsp, I'm creating the form like this:</p>
  
  <pre><code>&lt;form:form method="post" commandName="myCommand"&gt;
  
      &lt;c:forEach items="${model.availableitems}" var="item"&gt;
        &lt;span class="item"&gt;${item.description}&lt;/span&gt; 
        &lt;input type="hidden" name="id" value="${item.ID}"/&gt;
        &lt;input type="submit" name="SelectButton" value="Select" /&gt;
      &lt;/c:forEach&gt;
  
    &lt;/div&gt; 
  &lt;/form:form&gt;
  </code></pre>
  
  <p>However, this gives me a "Data binding errors: 1" message in the log and the form isn't submitted to the controller.  </p>
  
  <p>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.  </p>
  
  <p>How can I have multiple buttons in this form and get the value in the controller?</p>