FileDocCategorySizeDatePackage
CreateOrderAction.javaAPI DocJBoss 4.2.12432Fri Jul 13 20:56:06 BST 2007xpetstore.web.struts.action.order

CreateOrderAction

public class CreateOrderAction extends xpetstore.web.struts.action.BaseAction
author
Herve Tchepannou
struts.action
name="orderForm" path="/createOrder" scope="request" validate="false"
struts.action-forward
name="success" path="/confirmation.jsp"

Fields Summary
Constructors Summary
Methods Summary
protected org.apache.struts.action.ActionForwarddoExecute(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

see
xpetstore.web.struts.action.BaseAction#doExecute(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse)

       try 
       {
       System.out.println("!!CreateOrderAction.doExecute");
        OrderForm     frm = ( OrderForm ) form;
        String        userId = ( String ) request.getSession(  ).getAttribute( USERID_KEY );
        Petstore petstore = getPetstore(  );

        /* Proceed the order */
        HashMap items = new HashMap(  );

        for ( int i = 0, len = frm.getItemId(  ).length; i < len; i++ )
        {
            items.put( frm.getItemId(  )[ i ], new Integer( frm.getQuantity(  )[ i ] ) );
        }

        Integer orderUId = petstore.createOrder( userId, new Date(  ), items );
        frm.getOrder(  ).setOrderUId( orderUId );

        /* Invalidating the current cart */
        Cart cart = getCart( false, request );

        if ( cart != null )
        {
            request.getSession(  ).removeAttribute( CART_KEY );
            cart.remove(  );
        }

        return mapping.findForward( SUCCESS );
       }
       catch (Exception e)
       {
          e.printStackTrace();
          throw e;
       }