コード例 #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 downloading hotel contract
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  public ActionForward download(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    HotelContract hotelContract = this.getHotelContractFromRequest(request);
    Hotel hotel = hotelContract.getHotel();
    this.checkHotel(hotel, request);

    InputStream in =
        ServiceLocator.getHotelContractManager(request)
            .getHotelContractContent(hotelContract.getId());
    if (in != null) {
      try {
        if (hotelContract.getFileSize() == 0) {
          throw new ActionException("hotelContract.error.fileSize.zero");
        } else {
          DownloadUploadHelper.download(
              in,
              hotelContract.getFileName(),
              DownloadUploadHelper.getMime(hotelContract.getFileName()),
              hotelContract.getFileSize(),
              request,
              response,
              true);
        }
      } finally {
        in.close();
      }
    }
    return null;
  }
コード例 #3
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");
  }
コード例 #4
0
  /**
   * the action method for editing hotel contract
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  public ActionForward edit(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    HotelContract hotelContract = getHotelContractFromRequest(request);
    Hotel hotel = hotelContract.getHotel();

    this.checkHotel(hotel, request);

    request.setAttribute("x_hotelContract", hotelContract);

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