@RequestMapping("/detail")
  public ModelAndView detail(
      @RequestParam("id") int id,
      @RequestParam(value = "message", required = false) String message) {
    ModelAndView result;

    try {
      Tutorial tutorial = tutorialService.findOne(id);
      String requestURI = "tutorial/detail.do?id=" + id;
      boolean canRegister = tutorialService.canRegister(id);
      boolean editable = tutorialService.canEdit(id);
      boolean canComment = commentService.canCommentTutorial(id);

      result = new ModelAndView("tutorial/detail");

      result.addObject("tutorial", tutorial);
      result.addObject("requestURI", requestURI);
      result.addObject("canRegister", canRegister);
      result.addObject("canComment", canComment);
      result.addObject("editable", editable);
      if (message != null) {
        result.addObject("message", message);
      }
    } catch (DPNotFoundException e) {
      result = new ModelAndView("404");
    } catch (Throwable e) {
      result = new ModelAndView("error");
    }

    return result;
  }
  private ModelAndView createEditModelAndView() {
    ModelAndView result;
    TutorialForm tutorialForm = tutorialService.createForm();
    String previousURI = "";
    Collection<Subject> subjects = subjectService.findAll();

    result = new ModelAndView("tutorial/edit");

    result.addObject("tutorialForm", tutorialForm);
    result.addObject("previousURI", previousURI);
    result.addObject("subjects", subjects);

    return result;
  }
  @RequestMapping(value = "edit", method = RequestMethod.POST, params = "save")
  public ModelAndView save(@Valid TutorialForm tutorialForm, BindingResult binding) {
    ModelAndView result;
    if (binding.hasErrors()) {
      result = createEditModelAndView(tutorialForm);
    } else {
      try {
        Tutorial tutorial = tutorialService.reconstruct(tutorialForm);
        Tutorial dbTutorial = tutorialService.save(tutorial);
        result = new ModelAndView("redirect:detail.do?id=" + dbTutorial.getId());
      } catch (DPForbiddenException exc) {
        result = new ModelAndView("403");
      } catch (DPInvalidRegistrationException exc) {
        result = createEditModelAndView(tutorialForm);

        result.addObject("message", exc.getMessage());
      } catch (Throwable exc) {
        result = createEditModelAndView(tutorialForm);
        result.addObject("message", "commit.error");
      }
    }

    return result;
  }
  @RequestMapping("/edit")
  public ModelAndView edit(@RequestParam("idTutorial") int id) {
    ModelAndView result;

    try {
      TutorialForm tutorialForm = tutorialService.findToEdit(id);
      result = createEditModelAndView(tutorialForm);
    } catch (DPNotFoundException exc) {
      result = new ModelAndView("404");
    } catch (DPForbiddenException exc) {
      result = new ModelAndView("403");
    } catch (Throwable exc) {
      result = new ModelAndView("error");
    }

    return result;
  }
  @RequestMapping("/register")
  public ModelAndView register(@RequestParam("id") int id) {
    ModelAndView result;
    try {
      tutorialService.register(id);
      result = new ModelAndView("redirect:detail.do?id=" + id);
      result.addObject("message", "tutorial.successfully");
    } catch (DPNotFoundException exc) {
      result = new ModelAndView("404");
    } catch (DPForbiddenException e) {
      result = new ModelAndView("403");
    } catch (Throwable exc) {
      result = new ModelAndView("error");
    }

    return result;
  }