3

Model has Map(String,Integer), this map displayed on page in checkboxes like:

<ul>
  <li th:each="item : ${map}">
    <input type="checkbox" th:checked="${item.value} == 1" th:id="${item.key}"/>
    <label th:for="${item.key}" th:text="${item.key}"/>
  </li>
</ul>

How should i submit checkboxes state changes?

SKS
  • 123
  • 1
  • 10
  • I believe you need a wrapper object to hold the submitted data, like so: http://stackoverflow.com/a/36522177/3416320 – bpgriner Nov 17 '16 at 15:49

1 Answers1

1

If you are using Spring MVC as your application and Thymeleaf as your view engine please check out this section on dynamic forms and working with them:

http://www.thymeleaf.org/doc/tutorials/2.1/thymeleafspring.html#dynamic-fields

Essentially what you want to do is have an object that would have a Map as a variable within it, which would then bind all your inputs against when it hits the controller.

e.g.

public class MyObject {
    Map<String, Integer> myMap;

// getters and setters
}
Aeseir
  • 7,754
  • 10
  • 58
  • 107
  • It seems like usefull info, but it's not clearly for me how to use it in my situation. – SKS Oct 02 '15 at 08:28
  • You should brush up on your frameworks MVC a bit to understand how the information flows. Understanding how data is passed between view and controller is crucial to you understanding the solution and there isn't a simpler way to write/demonstrate it. – Aeseir Oct 02 '15 at 14:19