thymeleaf

Using thymeleaf, how to check a row in a table based on another pre-existing list?


folks...

Using Thymeleaf, it's possible to do something like that?

<tr th:each="body : ${bodies}"  >
    <td><input type="checkbox" th:value="${body.id}"
         th:checked="|${oUser.bodies.contains(__${body.id}__)}|"
        >
    </td>
    <td scope="row"><span th:text="${body.id}"> </span></td>
        <span th:text="${body.description}"></span>
    </td>
</tr>

I want to perform each body, but only check the input when my body.id == id of the logged user. How can I do that?


Solution

  • No need for preprocessing __${...}__ and in general, you shouldn't be nesting expressions like this: ${...${...}...}.

    <tr th:each="body : ${bodies}"  >
      <td>
        <input type="checkbox" th:value="${body.id}" th:checked="${oUser.bodies.contains(body.id)}" />
      </td>
      <td scope="row" th:text="${body.id}" />
      <td scope="row" th:text="${body.description}" />
    </tr>