mercredi 30 août 2017

Dynamic checkbox from list with Thymeleaf

I try to save the values from dynamically created checkboxes:

<div>
    <ul>
       <li th:each="item, stat : *{users}">
         <input type="checkbox" th:field="*{users[__${stat.index}__]}" th:value="${item}" />
         <label th:text="${item}"></label>
      </li>
   </ul>
</div>

The controller provides the String items as follwing:

public List<String> getUsers() {
    return users;
}

And the setter for the Strings is:

public void setUsers(final String[] users) {
    for (final String string : users) {
        System.out.println(string);
    }
}

The values are correct shown in the html page. But when i click save button, and the setter is called, the values are empty. What can i do, where is the problem? Any help would appreciate.




Aucun commentaire:

Enregistrer un commentaire