KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xpetstore > web > webwork > action > cart > AddItemAction


1 /*
2  * Created on 24-Feb-2003
3  */

4 package xpetstore.web.webwork.action.cart;
5
6 import java.util.Map JavaDoc;
7
8
9 /**
10  * @author <a HREF="mailto:tchbansi@sourceforge.net">Herve Tchepannou</a>
11  *
12  * @webwork.action
13  * name="addItem"
14  * success="cart.action"
15  */

16 public class AddItemAction
17     extends BaseCartAction
18 {
19     //~ Instance fields --------------------------------------------------------
20

21     private String JavaDoc _itemId;
22
23     //~ Methods ----------------------------------------------------------------
24

25     /**
26      * @see webwork.action.ActionSupport#doExecute()
27      */

28     protected String JavaDoc doExecute( )
29         throws Exception JavaDoc
30     {
31         Map JavaDoc cart = getCart( );
32         Integer JavaDoc qty = ( Integer JavaDoc ) cart.get( _itemId );
33
34         if ( qty == null )
35         {
36             cart.put( _itemId, new Integer JavaDoc( 1 ) );
37         }
38         else
39         {
40             cart.put( _itemId, new Integer JavaDoc( 1 + qty.intValue( ) ) );
41         }
42
43         return SUCCESS;
44     }
45
46     /**
47      * @return String
48      */

49     public String JavaDoc getItemId( )
50     {
51         return _itemId;
52     }
53
54     /**
55      * Sets the itemId.
56      * @param itemId The itemId to set
57      */

58     public void setItemId( String JavaDoc itemId )
59     {
60         _itemId = itemId;
61     }
62 }
63
Popular Tags