Search code examples
javaspringspring-mvcthymeleaf

Thymeleaf - Spring MVC. Form backing bean with boolean and checkboxes


Iam trying post a simple form to a spring controller using a thymeleaf. The backing bean includes a boolean value which is mapped to a checkbox in the template using th:field inside of a th:object tag. When I take a look at the rendered html DOM, spring mvc is adding an hidden input field, where the name is _attributeName. The name of the main input field is generated as attributeName. Now when Iam trying to post the form it aborts with a 400 because the request parameter _attributeName cant be mapped to a backing bean object (simply doesnt exist). So in addition the request wohld include attributeName as well as _attributeName. Why is this happening?


Solution

  • So i finally solved it. The Problem was, that I used boolean instead of Boolean and my getter where named like isEnabled instead of getEnabled. This seemed to cause the problem with the mapping between the form element and the backing bean.