Skip to main content

Thymeleaf hidden field value


Thymeleaf gives us almost everything we need. But there are some cases that thymeleaf does not work properly.
When we have a hidden field and we want to assign it a value, strangely thymeleaf will ignore the value property.

Use th:attr

<tr th:each="user, stat : ${users}">    <input type="hidden"           th:attr="name='userDtos[' + ${stat.index} + '].userId'"           th:value="${}" />    <!--some other inputs-->    <td>        <input type="checkbox" th:field="*{userDtos[__${stat.index}__].active}" />    </td></tr>