Everyone!
I'm new to Spring and Thymeleaf and I'm currently stuck. What I try ist to copy checked values from one HTML table to another (later on the values will be passed to be stored in MySQL table.
I tried different approaches but nothing works and I get exasperated with this problem. I really hope you can help me:
This Works: (it's not what's required though)
<tr th:id="${cList.zoneId}" th:each="cList, rowStat: ${countryZoneList}" class="clickable-row">
<td><input th:for="${cList.zoneId}" type="checkbox" th:name="zones" th:value="${cList.zoneId}" /></td>
<td th:text="${cList.zoneSymbol}"></td>
<td th:text="${cList.zoneName}"></td>
<td class="hiddenColumn" th:id="${cList.zoneId}"></td>
</tr>
:Controller:
@RequestMapping(value="/confirmCountries", method = RequestMethod.GET)
public String confirmCountriesPost(
HttpServletRequest request,
@ModelAttribute("zones") String zones,
Model model, Principal principal
) throws Exception {
System.out.println("zones: >>>>>>>>>>>>>>>>>>" + zones);
return "my-dashboard";
}
Here I get the expected printout: 3 (value from the first zoneId) I don't need the other values. I indeed need only the integer values, meaning the values of the 'selected' checkboxes.
What doesn't work
<tr th:id="${cList.zoneId}" th:each="cList, rowStat: ${countryZoneList}" class="clickable-row">
<td><input th:for="${cList.zoneId}" type="checkbox" th:name="zones" th:value="${cList.zoneId}"/></td>
<td th:text="${cList.zoneSymbol}"></td>
<td th:text="${cList.zoneName}"></td>
<td class="hiddenColumn" th:id="${cList.zoneId}"></td>
</tr>
Neither works this:
<tr th:id="${cList.zoneId}" th:each="cList, rowStat: ${countryZoneList}" class="clickable-row">
<td><input th:for="${cList.zoneId}" type="checkbox" th:field="*{zones}" th:value="${cList.zoneId}"/></td>
<td th:text="${cList.zoneSymbol}"></td>
<td th:text="${cList.zoneName}"></td>
<td class="hiddenColumn" th:id="${cList.zoneId}"></td>
</tr>
: Controller:
@RequestMapping(value="/confirmCountries", method = RequestMethod.GET)
public String confirmCountriesPost(
HttpServletRequest request,
@ModelAttribute("zones") ArrayList<String> zones,
Model model, Principal principal
) throws Exception {
System.out.println("zones: >>>>>>>>>>>>>>>>>>" + zones.size());
return "my-dashboard";
}
So here I try to store multiple values (the whole list) of selected values from the form to this ArrayList. The problem is, that even, when I check multiple checboxes ny ArrayList shows always the size of 1 (it stores only the first value). Where is the problem? Please help. How do I get the whole list of my 'cList.zoneI' values? Where is my mistake?
Thank you ion advance,
Dario
Aucun commentaire:
Enregistrer un commentaire