--- /dev/null
+package de.juplo.demo;
+
+
+import java.util.HashMap;
+import java.util.Map;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+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;
+
+
+/**
+ *
+ * @author Kai Moritz
+ */
+@Controller
+public class DemoController
+{
+ private static final Logger LOG =
+ LoggerFactory.getLogger(DemoController.class);
+
+
+ @RequestMapping("/")
+ public String display(
+ @ModelAttribute("form") Map<Integer, Map<String, Boolean>> form)
+ {
+ for (Integer id : form.keySet())
+ for (String entry : form.get(id).keySet())
+ LOG.info("{} - {}: {}", id, entry, form.get(id).get(entry));
+
+ return "form";
+ }
+
+ @RequestMapping(path = "/", params = "row")
+ public String addRow(
+ @ModelAttribute("form") Map<Integer, Map<String, Boolean>> form,
+ @RequestParam Integer row)
+ {
+ LOG.info("Adding row #{}", row);
+ form.put(row, new HashMap<>());
+ return "form";
+ }
+
+ @RequestMapping(path = "/", params = "row")
+ public String removeRow(
+ @ModelAttribute("form") Map<Integer, Map<String, Boolean>> form,
+ @RequestParam Integer row)
+ {
+ Map<String, Boolean> content = form.remove(row);
+ LOG.info("Removed row #{} with content: {}", row, content);
+ return "form";
+ }
+
+ @RequestMapping(path = "/", params = { "row", "entry" })
+ public String addEntry(
+ @ModelAttribute("form") Map<Integer, Map<String, Boolean>> form,
+ @RequestParam Integer row,
+ @RequestParam String entry)
+ {
+ LOG.info("Adding entry {} to row #{}", entry, row);
+ form.get(row).put(entry, Boolean.FALSE);
+ return "form";
+ }
+
+ @RequestMapping(path = "/", params = { "row", "entry" })
+ public String removeEntry(
+ @ModelAttribute("form") Map<Integer, Map<String, Boolean>> form,
+ @RequestParam Integer row,
+ @RequestParam String entry)
+ {
+ Boolean value = form.get(row).remove(entry);
+ LOG.info("Removed entry {} with value {} from row #{}", entry, value, row);
+ return "form";
+ }
+}