Implemented a form with a single checkbox to study its behavior
authorKai Moritz <kai@juplo.de>
Tue, 21 Jan 2020 21:27:20 +0000 (22:27 +0100)
committerKai Moritz <kai@juplo.de>
Fri, 7 Apr 2023 11:15:40 +0000 (13:15 +0200)
pom.xml
src/main/java/de/juplo/demo/DemoController.java [new file with mode: 0644]
src/main/java/de/juplo/demo/Form.java [new file with mode: 0644]
src/main/resources/application.properties
src/main/resources/templates/form.html [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
index fa19ce0..0ad8f78 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-webflux</artifactId>
                </dependency>
+               <dependency>
+                       <groupId>org.projectlombok</groupId>
+                       <artifactId>lombok</artifactId>
+                       <scope>provided</scope>
+               </dependency>
 
                <dependency>
                        <groupId>org.springframework.boot</groupId>
diff --git a/src/main/java/de/juplo/demo/DemoController.java b/src/main/java/de/juplo/demo/DemoController.java
new file mode 100644 (file)
index 0000000..483ca88
--- /dev/null
@@ -0,0 +1,24 @@
+package de.juplo.demo;
+
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+
+/**
+ * Controller to demonstrate the behavior of the checkbox
+ * @author Kai Moritz
+ */
+@Controller
+@Slf4j
+public class DemoController
+{
+  @RequestMapping("/")
+  public String display(@ModelAttribute Form form)
+  {
+    log.info("option={}", form.option);
+    return "form";
+  }
+}
diff --git a/src/main/java/de/juplo/demo/Form.java b/src/main/java/de/juplo/demo/Form.java
new file mode 100644 (file)
index 0000000..5bd5388
--- /dev/null
@@ -0,0 +1,15 @@
+package de.juplo.demo;
+
+
+import lombok.Data;
+
+
+/**
+ * Simple form with a single checkbox
+ * @author Kai Moritz
+ */
+@Data
+public class Form
+{
+  Boolean option;
+}
diff --git a/src/main/resources/templates/form.html b/src/main/resources/templates/form.html
new file mode 100644 (file)
index 0000000..b04d254
--- /dev/null
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html lang="en" xmlns:th="http://www.thymeleaf.org">
+  <head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
+    <title>Demo: Behavior Of A Checkbox</title>
+    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
+  </head>
+  <body>
+    <nav class="navbar navbar-dark bg-primary navbar-expand navbar-dark flex-column">
+      <h1 class="navbar-brand">Demo: Behavior Of A Checkbox</h1>
+    </nav>
+    <main class="container mt-5">
+      <form action="#" th:action="@{/}" th:object="${form}" method="get">
+        <div class="card my-3">
+          <div class="card-header">Select / unselect the option and submit the form...</div>
+          <div class="card-body">
+            <div class="card-text">
+              <div class="form-group">
+                <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>
+          </div>
+          <div class="card-footer">
+            <button type="submit" class="btn btn-primary">Submit</button>
+          </div>
+        </div>
+      </form>
+    </main>
+  </body>
+</html>