package ems.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;

import ems.service.TodoService;

@Controller
@SessionAttributes("name")
public class TodoController {
    @Autowired
    private TodoService mTodoService;

    @RequestMapping(value = "/list-todos", method = RequestMethod.GET)
    public String showTodosList(ModelMap model) {
        String user = (String) model.get("name");
        model.addAttribute("todos", mTodoService.retrieveTodos(user));
        return "list-todos";
    }

    @RequestMapping(value = "/add-todo", method = RequestMethod.GET)
    public String showTodoPage() {
        return "todo";
    }

    @RequestMapping(value = "/add-todo", method = RequestMethod.POST)
    public String addTodo(ModelMap model, @RequestParam String desc) {
        mTodoService.addTodo((String) model.get("name"), desc, new Date(), false);
        model.clear();
        return "redirect:/list-todos";
    }

    @RequestMapping(value = "/delete-todo", method = RequestMethod.GET)
    public String deleteTodo(@RequestParam int id) {
        mTodoService.deleteTodo(id);
        return "redirect:/list-todos";
    }
}

@@ -42,16 +42,104 @@
 .Date;%0A%0A
+import javax.validation.Valid;%0A%0Aimport ems.model.Todo;%0Aimport ems.service.TodoService;%0A%0A
 import o
@@ -283,16 +283,69 @@
 delMap;%0A
+import org.springframework.validation.BindingResult;%0A
 import o
@@ -593,41 +593,8 @@
 s;%0A%0A
-import ems.service.TodoService;%0A%0A
 @Con
@@ -1077,24 +1077,27 @@
  String show
+Add
 TodoPage() %7B
@@ -1093,19 +1093,81 @@
 odoPage(
-) %7B
+ModelMap model) %7B%0A        model.addAttribute(%22todo%22, new Todo());
 %0A       
@@ -1306,35 +1306,118 @@
 l, @
-RequestParam String desc) %7B
+Valid Todo todo, BindingResult result) %7B%0A        if(result.hasErrors()) %7B%0A            return %22todo%22;%0A        %7D
 %0A   
@@ -1474,12 +1474,22 @@
 %22), 
-d
+todo.getD
 esc
+()
 , ne

Add hibernate validator to TodoController