コード例 #1
0
  @RequestMapping(value = "/shift/{shiftId}/edit", method = RequestMethod.POST)
  public ModelAndView editShift(
      @PathVariable("shiftId") final Integer shiftId,
      @Valid @ModelAttribute("shift") Shift shift,
      BindingResult result) {
    ModelAndView mav = new ModelAndView();

    if (result.hasErrors()) {
      return new ModelAndView("shift/create", "shift", shift);
    }

    Event event = eventService.get(shift.getEvent().getId());

    // Set Dates to today
    shift.setStartTime(convertDateToToday(shift.getStartTime(), event.getDate()));
    shift.setEndTime(convertDateToToday(shift.getEndTime(), event.getDate()));

    try {
      shiftService.edit(shift);
    } catch (NotValidException e) {
      LOGGER.warn(e);
      result.addAllErrors(e.getErrors());
      return new ModelAndView("shift/create", "shift", shift);
    }

    return new ModelAndView("redirect:/event/" + shift.getEvent().getId() + "/edit");
  }
コード例 #2
0
  @RequestMapping(value = "/shift/{shiftId}/edit", method = RequestMethod.GET)
  public ModelAndView editShift(@PathVariable("shiftId") final Integer shiftId) {
    ModelAndView mav = new ModelAndView("shift/edit");

    mav.addObject("shift", shiftService.get(shiftId));

    return mav;
  }