?? carthtmlaction.java
字號:
} else if (actionType.equals("cancel")) { AdventureComponentManager acm = (AdventureComponentManager)session.getAttribute(AdventureKeys.COMPONENT_MANAGER); Cart cart = acm.getCart(session); cart.clear(); // remove these attributes used by the side bar session.removeAttribute("theCategory"); session.removeAttribute("categoryId"); } else if (actionType.equals("update")) { // not for beta } return null; } private void updateActivityHeadCounts(HttpServletRequest request) { HttpSession session = request.getSession(); // look up the cart AdventureComponentManager acm = (AdventureComponentManager)session.getAttribute(AdventureKeys.COMPONENT_MANAGER); Cart cart = acm.getCart(session); Map params = (Map)request.getParameterMap(); if (params.isEmpty()) return; Collection keys = params.keySet(); if (keys == null) return; Iterator it = keys.iterator(); while(it.hasNext() ) { String key = (String)it.next(); if (key.startsWith("headcount_")) { String id = key.substring("headcount_".length(), key.length()); String value = request.getParameter(key); int qty = (new Integer(value)).intValue(); cart.setActivityHeadCount(id,qty); } } } private void purchaseActivities(HttpServletRequest request) { HttpSession session = request.getSession(); // look up the cart AdventureComponentManager acm = (AdventureComponentManager)session.getAttribute(AdventureKeys.COMPONENT_MANAGER); Cart cart = acm.getCart(session); Map params = (Map)request.getParameterMap(); if (params == null) return; Collection keys = params.keySet(); if (keys == null) return; Iterator it = keys.iterator(); while(it.hasNext() ) { String key = (String)it.next(); if (key.startsWith("activity_")) { String id = key.substring("activity_".length(), key.length()); String value = request.getParameter(key); id = id.trim(); int qty = 0; try { if (value != null) qty = (new Integer(value)).intValue(); } catch (NumberFormatException nex) {} if (qty > 0) { cart.addActivity(id,qty); } else { cart.setActivityHeadCount(id,0); } } } } private void updatePackage(HttpServletRequest request) { HttpSession session = request.getSession(); // look up the cart AdventureComponentManager acm = (AdventureComponentManager)session.getAttribute(AdventureKeys.COMPONENT_MANAGER); Cart cart = acm.getCart(session); String adventureDaysString = request.getParameter("adventure_days"); if (adventureDaysString != null) { int adventureDays = (new Integer(adventureDaysString)).intValue(); cart.setAdventureDays(adventureDays); } String lodgingRoomCountString = request.getParameter("lodging_room_count"); if (lodgingRoomCountString != null) { int lodingRoomCount = (new Integer(lodgingRoomCountString)).intValue(); cart.setLodgingRoomCount(lodingRoomCount); } String headCountString = request.getParameter("head_count"); if (headCountString != null) { int headCount = (new Integer(headCountString)).intValue(); cart.setHeadCount(headCount); } // update the departureDate if specified if (request.getParameter("start_month") != null) { int startMonth = Integer.parseInt(request.getParameter("start_month")); int startDay = Integer.parseInt(request.getParameter("start_day")); int startYear = Integer.parseInt(request.getParameter("start_year")); Calendar c = Calendar.getInstance(); c.set(Calendar.MONTH, startMonth -1); c.set(Calendar.YEAR, startYear); c.set(Calendar.DAY_OF_MONTH, startDay); cart.setDepartureDate(c); } } private void getResultBean(HttpServletRequest request) throws HTMLActionException { double grandTotal = 0; double cartTotal = 0; double lodgingTotal = 0; double activityTotal = 0; double departureTotal = 0; double returnTotal = 0; double transportationTotal = 0; int adventureDays =0; int lodgingDays=0; int headCount = 0; int lodgingRoomCount = 1; HttpSession session = request.getSession(); AdventureComponentManager acm = (AdventureComponentManager)session.getAttribute(AdventureKeys.COMPONENT_MANAGER); Cart cart = acm.getCart(session); CatalogFacade facade = acm.getCatalogFacade(session); try { // locale will change after beta Locale locale = new Locale("en","us"); //assume the the user uses the same hotel for every night of the adventure lodgingDays = cart.getLodgingDays(); // this needs to be multiplied by the number of rooms lodgingRoomCount = cart.getLodgingRoomCount(); com.sun.j2ee.blueprints.catalog.Lodging lodging = facade.getLodging(cart.getLodgingId(), locale); lodgingTotal = (lodgingDays * lodging.getPrice() * lodgingRoomCount); // add in the actvities HashMap activities = cart.getActivities(); Iterator it = null; if (activities != null) it = activities.keySet().iterator(); while ((it != null) && it.hasNext()) { String itemId = (String)it.next(); Integer qty = (Integer)activities.get(itemId); com.sun.j2ee.blueprints.catalog.Activity item = facade.getActivity(itemId, locale); activityTotal += (qty.intValue() * item.getPrice()); } headCount = cart.getHeadCount(); if (cart.getDepartureFlight() != null) { com.sun.j2ee.blueprints.catalog.Transportation departureFlight = facade.getTransportation(cart.getDepartureFlight(), locale); if (departureFlight != null) { departureTotal = (departureFlight.getPrice() * headCount); } } if (cart.getReturnFlight() != null) { com.sun.j2ee.blueprints.catalog.Transportation returnFlight = facade.getTransportation(cart.getReturnFlight(), locale); if (returnFlight != null) { returnTotal = (returnFlight.getPrice() * headCount); } } transportationTotal = departureTotal + returnTotal; } catch (Exception ex) { throw new HTMLActionException("CartHTMLAction error: " + ex); } cartTotal = activityTotal + lodgingTotal + transportationTotal; CartBean bean = new CartBean(cartTotal, lodgingTotal, activityTotal, transportationTotal, lodgingDays, adventureDays, cart.getDepartureDate()); request.setAttribute(AdventureKeys.CART_BEAN, bean); }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -