/** * 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"); }
private HotelContract getHotelContractFromRequest(HttpServletRequest request) throws Exception { Integer id = ActionUtils.parseInt(request.getParameter("id")); HotelContractManager hotelContractManager = ServiceLocator.getHotelContractManager(request); HotelContract hotelContract = hotelContractManager.getHotelContract(id); if (hotelContract == null) throw new ActionException("hotelContract.notFound", id); return hotelContract; }
/** * the action method for searching hotel contract * * @param mapping * @param form * @param request * @param response * @return * @throws Exception */ public ActionForward list( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { HotelContractQueryForm queryForm = (HotelContractQueryForm) form; getHotelFromRequest(request); Map conditions = constructQueryMap(queryForm); HotelContractManager fm = ServiceLocator.getHotelContractManager(request); List result = fm.getHotelContractList(conditions, 0, -1, HotelContractQueryOrder.ID, false); request.setAttribute("X_RESULTLIST", result); return mapping.findForward("page"); }
/** * the action method for updating hotel contract * * @param mapping * @param form * @param request * @param response * @return * @throws Exception */ public ActionForward update( 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); HotelContractManager hotelContractManager = ServiceLocator.getHotelContractManager(request); request.setAttribute("X_OBJECT", hotelContractManager.updateHotelContract(hotelContract)); request.setAttribute("X_ROWPAGE", "hotelContract/row.jsp"); return mapping.findForward("success"); }