Added a checkbox, that is stored in a field of an inner class
authorKai Moritz <kai@juplo.de>
Tue, 21 Jan 2020 22:12:17 +0000 (23:12 +0100)
committerKai Moritz <kai@juplo.de>
Fri, 7 Apr 2023 11:15:40 +0000 (13:15 +0200)
src/main/java/de/juplo/demo/DemoController.java
src/main/java/de/juplo/demo/Form.java
src/main/resources/templates/form.html

index 483ca88..3f8d0dd 100644 (file)
@@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 
 
 /**
- * Controller to demonstrate the behavior of the checkbox
+ * Controller to demonstrate the behavior of checkboxes
  * @author Kai Moritz
  */
 @Controller
@@ -18,7 +18,7 @@ public class DemoController
   @RequestMapping("/")
   public String display(@ModelAttribute Form form)
   {
-    log.info("option={}", form.option);
+    log.info("option={}, inner={}", form.option, form.inner.option);
     return "form";
   }
 }
index 5bd5388..e7a40af 100644 (file)
@@ -5,11 +5,18 @@ import lombok.Data;
 
 
 /**
- * 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;
 }
index b04d254..10ebfaa 100644 (file)
                 <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">