title: Spring form validate : Whitelabel Error Page
body: <pre><code>    @RequestMapping(method = RequestMethod.GET, value = "/add")
      public ModelAndView add() throws ConferenceNotFoundException {
          LOGGER.debug("Getting adding page");
          return new ModelAndView("conference/add", "form", new ConferenceForm());
      }
  
      @RequestMapping(method = RequestMethod.POST, value = "/add")
      public String handleAddConferenceForm(@Valid @ModelAttribute("form") ConferenceForm form,
                                            BindingResult bindingResult,
                                            @ModelAttribute("currentUser") CurrentUser currentUser) {
          LOGGER.debug("Processing add conference form={}, bindingResult={}", form, bindingResult);
  
          form.setHost(currentUser.getUser());
  
          if (bindingResult.hasErrors()) {
              // failed validation
              return "conference/add";
          }
          try {
              conferenceService.create(form);
          } catch (Exception e) {
              e.printStackTrace();
          }
  
          // ok, redirect
          return "redirect:/";
      }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/ynVT6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ynVT6.png" alt="enter image description here"></a></p>
  
  <p>I make spring form like above the code. And it works well like above the picture.</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.GET, value = "/{id}/admin/update")
  public ModelAndView update(Model model,
                             @PathVariable("id") Long id) throws ConferenceNotFoundException {
      LOGGER.debug("Getting update page");
  
      Conference conference = conferenceService.findById(id);
      model.addAttribute("conference", conference);
      return new ModelAndView("conference/update", "form", new ConferenceForm(conference));
  }
  
  @RequestMapping(method = RequestMethod.POST, value = "/{id}/admin/update")
  public String handleUpdateConferenceForm(@Valid @ModelAttribute("form") ConferenceForm form,
                                           @PathVariable("id") Long id,
                                           BindingResult bindingResult,
                                           @ModelAttribute("currentUser") CurrentUser currentUser) {
      LOGGER.debug("Processing update conference form={}, bindingResult={}", form, bindingResult);
  
      form.setHost(currentUser.getUser());
  
      if (bindingResult.hasErrors()) {
          // failed validation
          return "conference/update";
      }
      try {
          conferenceService.update(form, id);
      } catch (Exception e) {
          e.printStackTrace();
      }
  
      // ok, redirect
      return "redirect:/conferences/" + id + "/admin";
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/lr5oj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lr5oj.png" alt="enter image description here"></a></p>
  
  <p>Otherwise, above the code does not work well. It's validator works well and it update the contents. But it generate <code>Whitelabel Error Page</code> when validator works.</p>
  
  <p>I don't know why it generate <code>Whitelabel Error Page</code>.</p>