KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xpetstore > web > webwork > action > category > CategoryAction


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

4 package xpetstore.web.webwork.action.category;
5
6 import java.util.Iterator JavaDoc;
7
8 import cirrus.hibernate.Session;
9
10 import xpetstore.domain.Category;
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="category"
21  * success="category.vm"
22  */

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

28     private Category _category = null;
29     private String JavaDoc _categoryId = "";
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             _category = ( Category ) s.load( Category.class, _categoryId );
44
45             /*
46              * Since category.product is lazy loaded,
47              * traverse the collection to load all the product to display
48              */

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

68     public Category getCategory( )
69     {
70         return _category;
71     }
72
73     /**
74      * @return String
75      */

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

85     public void setCategory( Category category )
86     {
87         _category = category;
88     }
89
90     /**
91      * Sets the categoryId.
92      * @param categoryId The categoryId to set
93      */

94     public void setCategoryId( String JavaDoc categoryId )
95     {
96         _categoryId = categoryId;
97     }
98 }
99
Popular Tags