KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xpetstore > web > struts > action > cart > CheckoutAction


1 package xpetstore.web.struts.action.cart;
2
3 import java.util.Collection JavaDoc;
4
5 import javax.servlet.http.HttpServletRequest JavaDoc;
6 import javax.servlet.http.HttpServletResponse JavaDoc;
7
8 import org.apache.struts.action.ActionForm;
9 import org.apache.struts.action.ActionForward;
10 import org.apache.struts.action.ActionMapping;
11
12 import xpetstore.domain.customer.ejb.Customer;
13
14 import xpetstore.services.cart.ejb.Cart;
15
16 import xpetstore.web.struts.action.BaseAction;
17
18
19 /**
20  * @author <a HREF="mailto:tchbansi@sourceforge.net">Herve Tchepannou</a>
21  *
22  * @struts.action
23  * name="cartForm"
24  * path="/checkout"
25  * scope="request"
26  * validate="false"
27  *
28  * @struts.action-forward
29  * name="success"
30  * path="/checkout.jsp"
31  */

32 public class CheckoutAction
33     extends BaseAction
34 {
35     //~ Methods ----------------------------------------------------------------
36

37     /**
38      * @see xpetstore.web.struts.action.BaseAction#doExecute(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse)
39      */

40     protected ActionForward doExecute( ActionMapping mapping,
41                                        ActionForm form,
42                                        HttpServletRequest JavaDoc request,
43                                        HttpServletResponse JavaDoc response )
44         throws Exception JavaDoc
45     {
46         String JavaDoc userId = ( String JavaDoc ) request.getSession( ).getAttribute( USERID_KEY );
47         CartForm frm = ( CartForm ) form;
48         Cart cart = getCart( request );
49
50         /* Order */
51         Customer cust = getPetstore( ).getCustomer( userId );
52         frm.setCustomer( cust );
53
54         /* Cart items */
55         Collection JavaDoc items = cart.getCartItems( );
56         frm.setCartItems( items );
57
58         /* Total */
59         frm.setTotal( cart.getTotal( ) );
60
61         return mapping.findForward( SUCCESS );
62     }
63 }
64
Popular Tags