I am not sure if this is your answer, but you can find an example at http://www.thymeleaf.org/doc/html/Thymeleaf-Spring3.html#checkbox-fields .
Here is a simple example illustrating the use of a checkbox in Thymeleaf using Spring MVC.
Controller:
@RequestMapping(value = "/showForm", method=RequestMethod.GET) public String showForm(Model model) { List<String> allItems = new ArrayList<String>(); allItems.add("value1"); allItems.add("value2"); allItems.add("value3"); model.addAttribute("allItems", allItems); Foo foo = new Foo(); List<String> checkedItems = new ArrayList<String>(); // value1 will be checked by default. checkedItems.add("value1"); foo.setCheckedItems(checkedItems); model.addAttribute("foo", foo); ... } @RequestMapping(value = "/processForm", method=RequestMethod.POST) public String processForm(@ModelAttribute(value="foo") Foo foo) { // Get value of checked item. List<String> checkedItems = foo.getCheckedItems(); ... }
HTML:
<form action="#" th:action="@{/processForm}" th:object="${foo}" method="post"> <div th:each="item : ${allItems}"> <input type="checkbox" th:field="*{checkedItems}" th:value="${item}" /> <label th:text="${item}">example</label> </div> <input type="submit" /> </form>
Foo.java:
public class Foo { private List<String> checkedItems; public List<String> getCheckedItems() { return checkedItems; } public void setCheckedItems(List<String> checkedItems) { this.checkedItems = checkedItems; } }
Hope this helps.
source share