コード例 #1
0
  /**
   * Setup a GET method form.
   *
   * @param id id of the controller
   * @param model data model
   * @return form continuation
   */
  @RequestMapping(method = RequestMethod.GET)
  public String setupForm(@PathVariable("id") String id, Model model) {
    SpaceController controller = controllerRepository.getSpaceControllerById(id);
    model.addAttribute("spacecontroller", SpaceControllerUtils.toTemplate(controller));
    model.addAttribute("id", id);
    addNeededEntities(model);

    addGlobalModelItems(model);

    return "spacecontroller/SpaceControllerEdit";
  }
コード例 #2
0
  /**
   * Process form submit request.
   *
   * @param id id of the controller
   * @param template data template to process
   * @param result binding result
   * @param status the session status
   * @return form continuation
   */
  @RequestMapping(method = {RequestMethod.PUT, RequestMethod.POST})
  public String processSubmit(
      @PathVariable("id") String id,
      @ModelAttribute("spacecontroller") SpaceController template,
      BindingResult result,
      SessionStatus status,
      Model model) {
    new SpaceControllerValidator().validate(template, result);
    if (result.hasErrors()) {
      addNeededEntities(model);
      return "spacecontroller/SpaceControllerEdit";
    } else {
      SpaceController controller = controllerRepository.getSpaceControllerById(id);
      SpaceControllerUtils.copy(template, controller);
      controllerRepository.saveSpaceController(controller);

      status.setComplete();

      return "redirect:/spacecontroller/" + controller.getId() + "/view.html";
    }
  }