KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xpetstore > web > webwork > action > product > ProductAction


1 /*
2  * Created on Feb 23, 2003
3  */

4 package xpetstore.web.webwork.action.product;
5
6 import java.util.Iterator JavaDoc;
7
8 import cirrus.hibernate.Session;
9
10 import xpetstore.domain.Item;
11 import xpetstore.domain.Product;
12
13 import xpetstore.web.webwork.action.BaseAction;
14
15
16 /**
17  * @author <a HREF="mailto:tchbansi@sourceforge.net">Herve Tchepannou</a>
18  *
19  * @webwork.action
20  * name="product"
21  * success="product.vm"
22  */

23 public class ProductAction
24     extends BaseAction
25 {
26     //~ Instance fields --------------------------------------------------------
27

28     private Product _product = null;
29     private String JavaDoc _productId = "";
30
31     //~ Methods ----------------------------------------------------------------
32

33     /**
34      * @see webwork.action.ActionSupport#doExecute()
35      */

36     protected String JavaDoc doExecute( )
37         throws Exception JavaDoc
38     {
39         Session s = getHibernateSession( );
40
41         try
42         {
43             _product = ( Product ) s.load( Product.class, _productId );
44
45             /*
46              * Since product.item is lazy loaded,
47              * traverse the collection to load all the product to display
48              */

49             Iterator JavaDoc it = _product.getItems( ).iterator( );
50
51             while ( it.hasNext( ) )
52             {
53                 Item i = ( Item ) it.next( );
54                 i.getDescription( );
55             }
56
57             return SUCCESS;
58         }
59         finally
60         {
61             s.close( );
62         }
63     }
64
65     /**
66      * @return Product
67      */

68     public Product getProduct( )
69     {
70         return _product;
71     }
72
73     /**
74      * @return String
75      */

76     public String JavaDoc getProductId( )
77     {
78         return _productId;
79     }
80
81     /**
82      * Sets the product.
83      * @param product The product to set
84      */

85     public void setProduct( Product product )
86     {
87         _product = product;
88     }
89
90     /**
91      * Sets the productId.
92      * @param productId The productId to set
93      */

94     public void setProductId( String JavaDoc productId )
95     {
96         _productId = productId;
97     }
98 }
99
Popular Tags