Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submit Map<String,Integer> Thymeleaf

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?

like image 470
SKS Avatar asked Dec 12 '25 13:12

SKS


1 Answers

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
}
like image 101
Aeseir Avatar answered Dec 14 '25 03:12

Aeseir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!