jeudi 18 août 2016

null checkbox selections from Thymeleaf

I have a list of people, represented with checkboxs, in my html form. When the user selects some of those people, and submits the form, my controller receives a List of null values for those selections, instead of the ID values in the html form. I think my binding result is misconfigured somehow.

enter image description here

My html...

<fieldset id="covered_deps">
 <legend>Covered Dependents</legend>
  <label class="col-xs-4"></label>
  <ul class="col-xs-8" th:classappend="${#fields.hasErrors('oa.dependents')} ? has-error">

    <li class="col-xs-8 checkbox" th:each="dep, stat : ${session.submission.uso.peopleNotOrgs()}"><input type="checkbox"
        th:checked="*{oa.containsCoveredDependent('__${dep.id}__')}" th:name="oa.dependents" th:value="${dep.id}" /> <label
        th:text="${dep.getSimpleDisplayName()}">Jr</label></li>
  </ul>
<span class="help-block" th:errors="*{oa.dependents}">[error]</span></fieldset>

My controller...

@RequestMapping(value = "/obli", method = RequestMethod.PUT)
public String updateObli(@Valid @ModelAttribute("obli") Obligation obli, BindingResult br, Model model, HttpSession session) { ...

Another method in my controller...

@InitBinder
public void initBinder(WebDataBinder binder, HttpSession session) {

    // obligation recipient [obligee]
    binder.registerCustomEditor(PersonOrOrg.class, new PersonOrOrgPropertyEditor(session));

    binder.registerCustomEditor(Payee.class, new PayeePropertyEditor(session));

    // covered dependents & obligor
    binder.registerCustomEditor(Person.class, new PersonPropertyEditor(session));
}

The weird thing is this, ... I have another collection of people represented with checkboxes in the form, just above this fieldset. That higher fieldset is working perfectly. And it uses the same controller methods because it is in the same html form. When I compare the rendered html source for these two fieldsets, they are nearly identical.

My Spring Boot parent version is "1.3.7.RELEASE".




Aucun commentaire:

Enregistrer un commentaire