1 package xpetstore.web.struts.action.order; 2 3 import java.util.Date ; 4 import java.util.HashMap ; 5 6 import javax.servlet.http.HttpServletRequest ; 7 import javax.servlet.http.HttpServletResponse ; 8 9 import org.apache.struts.action.ActionForm; 10 import org.apache.struts.action.ActionForward; 11 import org.apache.struts.action.ActionMapping; 12 13 import xpetstore.domain.order.ejb.Order; 14 import xpetstore.services.cart.ejb.Cart; 15 import xpetstore.services.petstore.ejb.Petstore; 16 17 import xpetstore.web.struts.action.BaseAction; 18 19 20 33 public class CreateOrderAction 34 extends BaseAction 35 { 36 38 41 protected ActionForward doExecute( ActionMapping mapping, 42 ActionForm form, 43 HttpServletRequest request, 44 HttpServletResponse response ) 45 throws Exception 46 { 47 try 48 { 49 System.out.println("!!CreateOrderAction.doExecute"); 50 OrderForm frm = ( OrderForm ) form; 51 String userId = ( String ) request.getSession( ).getAttribute( USERID_KEY ); 52 Petstore petstore = getPetstore( ); 53 54 55 HashMap items = new HashMap ( ); 56 57 for ( int i = 0, len = frm.getItemId( ).length; i < len; i++ ) 58 { 59 items.put( frm.getItemId( )[ i ], new Integer ( frm.getQuantity( )[ i ] ) ); 60 } 61 62 Integer orderUId = petstore.createOrder( userId, new Date ( ), items ); 63 frm.getOrder( ).setOrderUId( orderUId ); 64 65 66 Cart cart = getCart( false, request ); 67 68 if ( cart != null ) 69 { 70 request.getSession( ).removeAttribute( CART_KEY ); 71 cart.remove( ); 72 } 73 74 return mapping.findForward( SUCCESS ); 75 } 76 catch (Exception e) 77 { 78 e.printStackTrace(); 79 throw e; 80 } 81 } 82 } 83 | Popular Tags |