title: getting Ids from selected checkboxes in a table using Spring + Thymeleaf
body: <p>I'm getting an error NotReadablePropertyException: Invalid property 'userIds' of bean class [...ListOfIds]...  And I'm not sure why. If I remove the <code>th:field</code> attribute on the checkbox, the table fills in properly. I've tried with <code>th:field=&quot;*{requestIds}&quot;</code> and <code>th:field=&quot;*{requestIds.ids}&quot;</code>
  What I'm trying to do is collect the list of ids from the selected checkboxes and pass them back to the controller for the post.</p>
  <p>Form</p>
  <pre><code>public class ListOfIds {
     List&lt;Long&gt; ids = new ArrayList&lt;&gt;();
  
     public List&lt;Long&gt; getIds() { return ids; }
  // I've tried both set methods by themselves and together.
     public void setIds(List&lt;Long&gt; ids) { this.ids = ids; }
     public void setIds(Long[] ids) { this.ids = Arrays.asList(ids); }
  }
  </code></pre>
  <p>Request bean</p>
  <pre><code>public class Request {
     long id;
     String name;
     String phone;
     String email;
  
     // Getters/Setters
  }
  </code></pre>
  <p>Controller</p>
  <pre><code>@GetMapping(&quot;/myTable&quot;)
  public ModelAndView getMyTable(ModelAndView mav) {
     mav.setViewName(&quot;myTable&quot;);
     List&lt;Request&gt; requests = service.getRequests();
     mav.addObject(&quot;requests&quot;, requests);
     mav.addObject(&quot;requestIds&quot;, new ListOfIds());
     return mav;
  }
  
  @PostMapping(&quot;/myTable&quot;)
  public ModelAndView postRequests(ModelAndView mav, @ModelAttribute(&quot;requestIds&quot;) ListOfIds ids) {
     ...
  }
  </code></pre>
  <p>html page</p>
  <pre><code>...
  &lt;form method=&quot;post&quot; th:action=&quot;@{/myTable}&quot; th:object=&quot;${requestIds}&quot;&gt;
     &lt;table class=&quot;table ...&quot;&gt;
        &lt;thead&gt;
        &lt;tr&gt;
           &lt;th&gt;&lt;input type=&quot;checkbox&quot; class=&quot;selectall&quot; data-target=&quot;requests-all&quot;/&gt;&lt;/th&gt;
           &lt;th&gt;Name&lt;/th&gt;
           &lt;th&gt;Phone&lt;/th&gt;
           &lt;th&gt;Email&lt;/th&gt;
        &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody&gt;
        &lt;tr role=&quot;row&quot; th:each=&quot;request : ${requests}&quot;&gt;
           &lt;td&gt;
              &lt;input type=&quot;checkbox&quot; name=&quot;requestId&quot; data-target=&quot;requests-all&quot; 
                     th:value=&quot;${request.id}&quot; th:field=&quot;*{requestIds}&quot;/&gt;
           &lt;/td&gt;
           &lt;td th:text=&quot;${request.name}&quot;&gt;&lt;/td&gt;
           &lt;td th:text=&quot;${request.phone}&quot;&gt;&lt;/td&gt;
           &lt;td th:text=&quot;${request.email}&quot;&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;/tbody&gt;
     &lt;/table&gt;
     &lt;button class=&quot;btn btn-primary show-selected&quot;&gt;Process&lt;/button&gt;
  &lt;/form&gt;
  ...
  &lt;script&gt;
  $(document).ready(function() {
     $('button').click(function(e) {
        if !(confirm(&quot;Are you sure you wish to process these requests&quot;)) {
           e.preventDefault();
        }
     });
  });
  &lt;/script&gt;
  ...
  </code></pre>