/**
- * Controller to demonstrate the behavior of the checkbox
+ * Controller to demonstrate the behavior of checkboxes
* @author Kai Moritz
*/
@Controller
@RequestMapping("/")
public String display(@ModelAttribute Form form)
{
- log.info("option={}", form.option);
+ log.info("option={}, inner={}", form.option, form.inner.option);
return "form";
}
}
/**
- * Simple form with a single checkbox
+ * Simple form to demonstrate the behavior of checkboxes
* @author Kai Moritz
*/
@Data
public class Form
+{
+ Boolean option;
+ Inner inner = new Inner();
+}
+
+@Data
+class Inner
{
Boolean option;
}
<input type="checkbox" class="form-check-label" th:field="*{option}" />
<label class="form-check-label" th:for="${#ids.prev('option')}">Fancy Option To Choose</label>
</div>
+ <div class="form-group">
+ <input type="checkbox" class="form-check-label" th:field="*{inner.option}" />
+ <label class="form-check-label" th:for="${#ids.prev('inner.option')}">Another Option (In An Inner Class)</label>
+ </div>
</div>
</div>
<div class="card-footer">