コード例 #1
0
  @RequestMapping(
      value = "save",
      method = {RequestMethod.POST})
  public String save(
      @Valid @ModelAttribute Guest newGuest,
      BindingResult result,
      Model model,
      HttpServletResponse response) {

    if (result.hasErrors()) {
      GuestWrapper guestWrapper = guestService.getLocaleInformationForForm();

      model.addAttribute("countries", guestWrapper.getCountries());
      model.addAttribute("states", guestWrapper.getStates());
      model.addAttribute("cities", guestWrapper.getCities());

      GuestbookController.UNITEDSTATESCOUNTRYID = guestWrapper.getUnitedStates().getPk();
      GuestbookController.MASSACHUSETTSSTATEID = guestWrapper.getMassachusetts().getPk();

      return "guestbook";
    }

    guestService.addNewGuest(newGuest);
    emailService.sendThankyouEmail(newGuest.getEmail(), newGuest.getName());

    return "thankyou";
  }
コード例 #2
0
  @RequestMapping(
      value = "getGuestbookForm",
      method = {RequestMethod.GET})
  public String getGuestbookForm(Model model) {
    GuestWrapper guestWrapper = guestService.getLocaleInformationForForm();

    model.addAttribute("countries", guestWrapper.getCountries());
    model.addAttribute("states", guestWrapper.getStates());
    model.addAttribute("cities", guestWrapper.getCities());
    model.addAttribute("unitedStatesCountryID", guestWrapper.getUnitedStates().getPk());
    model.addAttribute("massachusettsStateID", guestWrapper.getMassachusetts().getPk());

    GuestbookController.UNITEDSTATESCOUNTRYID = guestWrapper.getUnitedStates().getPk();
    GuestbookController.MASSACHUSETTSSTATEID = guestWrapper.getMassachusetts().getPk();

    return "guestbook";
  }