Additionally options can be added dynamically
[demos/spring-boot] / src / main / java / de / juplo / demo / DemoController.java
index b841780..c74a6e9 100644 (file)
@@ -6,6 +6,8 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.thymeleaf.util.StringUtils;
 
 
 /**
@@ -30,4 +32,19 @@ public class DemoController
             .collect(Collectors.joining(", ", ", ", "")));
     return "form";
   }
+
+  @RequestMapping(path = "/", params = "add")
+  public String add(@ModelAttribute Form form, @RequestParam String name)
+  {
+    if (!StringUtils.isEmptyOrWhitespace(name))
+    {
+      form.map.put(name.trim(), Boolean.FALSE);
+      log.info("Added option \"{}\" to the map", name.trim());
+    }
+    else
+    {
+      log.info("Ignoring empty option-name");
+    }
+    return display(form);
+  }
 }