Пример #1
0
  /**
   * the action method for inserting new hotel contract to db
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  public ActionForward insert(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    Hotel hotel = this.getHotelFromRequest(request);
    this.checkHotel(hotel, request);

    BeanForm hotelContractForm = (BeanForm) form;
    HotelContract hotelContract = new HotelContract();
    hotelContractForm.populate(hotelContract, BeanForm.TO_BEAN);
    hotelContract.setHotel(hotel);

    FormFile file = (FormFile) hotelContractForm.get("fileContent");
    hotelContract.setFileName(file.getFileName());

    HotelContractManager hotelContractManager = ServiceLocator.getHotelContractManager(request);
    HotelContract newHc = null;
    if (file.getFileSize() > 0) {
      hotelContract.setFileSize(file.getFileSize());
      newHc = hotelContractManager.insertHotelContract(hotelContract, file.getInputStream());
    } else {
      throw new ActionException("hotelContract.error.fileSize.zero");
    }
    request.setAttribute("X_OBJECT", newHc);
    request.setAttribute("X_ROWPAGE", "hotelContract/row.jsp");

    return mapping.findForward("success");
  }
Пример #2
0
  /**
   * the action method for creating hotel contract
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  public ActionForward newObject(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    Hotel hotel = this.getHotelFromRequest(request);

    this.checkHotel(hotel, request);

    if (!isBack(request)) {
      HotelContract hotelContract = new HotelContract();
      hotelContract.setHotel(hotel);
      BeanForm hotelContractForm = (BeanForm) getForm("/insertHotelContract", request);
      hotelContractForm.populate(hotelContract, BeanForm.TO_FORM);
    }
    putEnumListToRequest(request);
    return mapping.findForward("page");
  }