title: Thymeleaf #lists.contains() expression utility not working
body: <p>I'm working with the thymeleaf standard dialect and trying to render a list of checkboxes in a form.  The rendering is ok, however, the problem is where I try to apply the "checked" property to the checkboxes using the thymeleaf #lists.contains() expression utility method.  </p>
  
  <p>So I have a model class that has the following fields:</p>
  
  <pre><code>private List&lt;Template&gt; templates;
  
  @FormParam("selectedTemplates")
  private List&lt;String&gt; selectedTemplates = Lists.newArrayList();
  </code></pre>
  
  <p>A Thymeleaf template html fragment:</p>
  
  <pre><code>&lt;div th:each="template : *{templates}"&gt;
      &lt;input type="checkbox" name="selectedTemplates" th:value="${template.id}" 
      th:checked="${#lists.contains(product.selectedTemplates, template.id)}" /&gt;
      &lt;label th:text="${template.filename} + ' (' + ${template.description} + ')'" /&gt;
      &lt;!-- Attempt to use the list contains to check the field --&gt;
      &lt;div th:text="${product.selectedTemplates}"/&gt;
      &lt;div th:text="${template.id}"/&gt;  
      &lt;div th:text="${#lists.contains(product.selectedTemplates, template.id)}" /&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The output on the page for one of the checkboxes that should be selected.</p>
  
  <pre><code>&lt;input type="checkbox" name="selectedTemplates" value="4" /&gt; (Template Name)
  &lt;div&gt;[4,5]&lt;/div&gt;
  &lt;div&gt;4&lt;/div&gt;
  &lt;div&gt;false&lt;div&gt;
  </code></pre>
  
  <p>So as you can see, I print the list which has values [4,5] and I use the #lists.contains method to see if it has template.id in it, however, the method always returns false. I even tried some hard coded ids to test the method and I always get "false" back.</p>
  
  <p>For example:</p>
  
  <pre><code>&lt;div th:text="${product.selectedTemplates}"/&gt;
  &lt;div th:text="${#lists.contains(product.selectedTemplates, 4)}" /&gt;
  </code></pre>
  
  <p>Prints [4,5]false</p>
  
  <pre><code>&lt;div th:text="${product.selectedTemplates}"/&gt;
  &lt;div th:text="${#lists.contains(product.selectedTemplates, '4')}" /&gt;
  </code></pre>
  
  <p>Prints [4,5]false</p>
  
  <p>Not sure what I'm doing wrong, but it seems so straight forward, not sure what else to try.  My guess is there is something wrong with the syntax.  Any suggestions or advice is greatly appreciated.  I'm not able to find any resources on troubleshooting this problem, the thymeleaf guide quickly glosses over that section.</p>