コード例 #1
0
  @RequestMapping(value = "/shift/{eventId}/create", method = RequestMethod.POST)
  public ModelAndView createShift(
      @PathVariable("eventId") final Integer eventId,
      @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(eventId);

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

    shift.setEvent(event);

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

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

    Shift shift = new Shift();
    shift.setEvent(eventService.get(eventId));

    mav.addObject("shift", shift);

    return mav;
  }