KickJava   Java API By Example, From Geeks To Geeks.

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


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="updateCart"
14  * success="cart.action"
15  */

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

21     private String JavaDoc _itemId[];
22     private int _quantity[];
23
24     //~ Methods ----------------------------------------------------------------
25

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

29     protected String JavaDoc doExecute( )
30         throws Exception JavaDoc
31     {
32         Map JavaDoc cart = getCart( );
33
34         for ( int i = 0; i < _quantity.length; i++ )
35         {
36             int qty = _quantity[ i ];
37
38             if ( qty <= 0 )
39             {
40                 cart.remove( _itemId[ i ] );
41             }
42             else
43             {
44                 cart.put( _itemId[ i ], new Integer JavaDoc( qty ) );
45             }
46         }
47
48         return SUCCESS;
49     }
50
51     /**
52      * @return String[]
53      */

54     public String JavaDoc[] getItemId( )
55     {
56         return _itemId;
57     }
58
59     /**
60      * @return int[]
61      */

62     public int[] getQuantity( )
63     {
64         return _quantity;
65     }
66
67     /**
68      * Sets the itemId.
69      * @param itemId The itemId to set
70      */

71     public void setItemId( String JavaDoc itemId[] )
72     {
73         _itemId = itemId;
74     }
75
76     /**
77      * Sets the quantity.
78      * @param quantity The quantity to set
79      */

80     public void setQuantity( int quantity[] )
81     {
82         this._quantity = quantity;
83     }
84 }
85
Popular Tags