title: Implement a button in a table that returns data from the table using Thymeleaf and Spring Boot
body: <p>tl;dr with Spring Boot and Thymeleaf, how do I return the column 1 value of the table in a form when the user clicks the button in column 5 of a particular row?</p>
  
  <p>Hi there!  Long time listener, first time caller.  I'd be much obliged for your help with this issue.</p>
  
  <p>I'm writing a server app using Spring Boot and Thymeleaf.  The server interacts with a number of devices.  I'm creating a web page that will show the list of devices and their IP addresses in a table (in a form). Each row of the table has info about the device and a "Remove" button to remove the device from the list.  When the button is clicked, the form should return the IP address of the device to the underlying Controller so the Controller can remove the device from the (internal) list of devices.</p>
  
  <p>I can get it to either return nothing at all, or ALL of the IP addresses (as a string with commas separating the values), but I can't get it to return ONLY the address on the row of the clicked button.</p>
  
  <p>The searches I've done have turned up ways to do it for static tables, but not dynamically generated ones, or for regular "input" type inputs, not buttons.  Nothing specific to click this button, return this value from the other column of the same row.</p>
  
  <p>I'm trying to do this in relatively pure Java and HTML, but I'm not opposed to some snippets of JavaScript if it solves the problem.  I don't really know anything about JQuery... and JSP pages are also not an option for other project reasons.</p>
  
  <p>HTML:</p>
  
  <pre><code>  &lt;form action="#" th:action="@{/webservice/adddevice}" th:object="${addForm}" method="post"&gt;
  &lt;table&gt;
      &lt;tr&gt;&lt;th&gt;Device IP&lt;/th&gt;
          &lt;th&gt;Status&lt;/th&gt;
          &lt;th&gt;Model Name&lt;/th&gt;
          &lt;th&gt;Serial No.&lt;/th&gt;
          &lt;th&gt;Remove?&lt;/th&gt;
      &lt;/tr&gt;
      &lt;tr th:each="d : ${devices}"&gt;
          &lt;td th:text="${d.address}"&gt;N/A&lt;/td&gt;
          &lt;td th:text="${d.status}"&gt;N/A&lt;/td&gt;
          &lt;td th:text="${d.modelName}"&gt;N/A&lt;/td&gt;
          &lt;td th:text="${d.serialno}"&gt;N/A&lt;/td&gt;
          &lt;td&gt;&lt;input type="hidden" th:value="${d.address}" name="deviceIP"/&gt;&lt;button type="submit" class="removebutton" name="action" value="remove"&gt;Remove&lt;/button&gt;&lt;/td&gt;
          &lt;td th:if="${#fields.hasErrors('deviceIP')}" th:errors="*{deviceIP}"&gt;IP Error&lt;/td&gt;
      &lt;/tr&gt; 
  &lt;/table&gt;
  </code></pre>
  
  <p></p>
  
  <p>My latest (and closest-to-the-mark) attempt uses the hidden input on each row to return the value... but it returns the value for ALL of the rows.</p>
  
  <p>The "devices" (class DeviceStatus) object is a List of your standard data object with a bunch of string members and get/set methods.  It holds the info for the attached devices.</p>
  
  <p>The "addForm" (class AddForm) object is a single object with a string ("deviceIP") and get/set methods for that string.</p>
  
  <p>The controller GET method:</p>
  
  <pre><code>    @RequestMapping(value="/webservice/adddevice", method=RequestMethod.GET)
  public String showForm(Model model, AddForm addForm) {
      model.addAttribute("devices", getDevicesStatus());
      addForm.loadPrefs(deviceController);
  return "adddevice"; // the webpage is adddevice.html
  }
  </code></pre>
  
  <p>and the controller POST method:</p>
  
  <pre><code>    @RequestMapping(value="/webservice/adddevice", method=RequestMethod.POST, params="action=remove")
  public String removeDevice(@Valid AddForm addForm, BindingResult bindingResult) {
  //addForm.removeDevice(deviceController);
  return "redirect:/webservice/results";
  }
  </code></pre>
  
  <p>For now the POST method doesn't do anything... until I get the HTML Form working, there's not much point.</p>