KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibatis > jpetstore > presentation > CatalogBean


1 package com.ibatis.jpetstore.presentation;
2
3 import com.ibatis.common.util.PaginatedList;
4 import com.ibatis.jpetstore.domain.Category;
5 import com.ibatis.jpetstore.domain.Item;
6 import com.ibatis.jpetstore.domain.Product;
7 import com.ibatis.jpetstore.service.CatalogService;
8 import com.ibatis.struts.ActionContext;
9 import com.ibatis.struts.BaseBean;
10
11 /**
12  * <p/>
13  * Date: Mar 9, 2004 10:16:59 PM
14  *
15  * @author Clinton Begin
16  */

17 public class CatalogBean extends BaseBean {
18
19   /* Constants */
20
21   private static final CatalogService catalogService = CatalogService.getInstance();
22
23   /* Private Fields */
24
25   private String JavaDoc keyword;
26   private String JavaDoc pageDirection;
27
28   private String JavaDoc categoryId;
29   private Category category;
30   private PaginatedList categoryList;
31
32   private String JavaDoc productId;
33   private Product product;
34   private PaginatedList productList;
35
36   private String JavaDoc itemId;
37   private Item item;
38   private PaginatedList itemList;
39
40   /* JavaBeans Properties */
41
42   public String JavaDoc getKeyword() {
43     return keyword;
44   }
45
46   public void setKeyword(String JavaDoc keyword) {
47     this.keyword = keyword;
48   }
49
50   public String JavaDoc getPageDirection() {
51     return pageDirection;
52   }
53
54   public void setPageDirection(String JavaDoc pageDirection) {
55     this.pageDirection = pageDirection;
56   }
57
58   public String JavaDoc getCategoryId() {
59     return categoryId;
60   }
61
62   public void setCategoryId(String JavaDoc categoryId) {
63     this.categoryId = categoryId;
64   }
65
66   public String JavaDoc getProductId() {
67     return productId;
68   }
69
70   public void setProductId(String JavaDoc productId) {
71     this.productId = productId;
72   }
73
74   public String JavaDoc getItemId() {
75     return itemId;
76   }
77
78   public void setItemId(String JavaDoc itemId) {
79     this.itemId = itemId;
80   }
81
82   public Category getCategory() {
83     return category;
84   }
85
86   public void setCategory(Category category) {
87     this.category = category;
88   }
89
90   public Product getProduct() {
91     return product;
92   }
93
94   public void setProduct(Product product) {
95     this.product = product;
96   }
97
98   public Item getItem() {
99     return item;
100   }
101
102   public void setItem(Item item) {
103     this.item = item;
104   }
105
106   public PaginatedList getCategoryList() {
107     return categoryList;
108   }
109
110   public void setCategoryList(PaginatedList categoryList) {
111     this.categoryList = categoryList;
112   }
113
114   public PaginatedList getProductList() {
115     return productList;
116   }
117
118   public void setProductList(PaginatedList productList) {
119     this.productList = productList;
120   }
121
122   public PaginatedList getItemList() {
123     return itemList;
124   }
125
126   public void setItemList(PaginatedList itemList) {
127     this.itemList = itemList;
128   }
129
130   /* Public Methods */
131
132   public String JavaDoc viewCategory() {
133     if (categoryId != null) {
134       productList = catalogService.getProductListByCategory(categoryId);
135       category = catalogService.getCategory(categoryId);
136     }
137     return "success";
138   }
139
140   public String JavaDoc searchProducts() {
141     if (keyword == null || keyword.length() < 1) {
142       ActionContext.getActionContext().setSimpleMessage("Please enter a keyword to search for, then press the search button.");
143       return "failure";
144     } else {
145       productList = catalogService.searchProductList(keyword.toLowerCase());
146       return "success";
147     }
148   }
149
150   public String JavaDoc switchProductListPage() {
151     if ("next".equals(pageDirection)) {
152       productList.nextPage();
153     } else if ("previous".equals(pageDirection)) {
154       productList.previousPage();
155     }
156     return "success";
157   }
158
159   public String JavaDoc viewProduct() {
160     if (productId != null) {
161       itemList = catalogService.getItemListByProduct(productId);
162       product = catalogService.getProduct(productId);
163     }
164     return "success";
165   }
166
167   public String JavaDoc switchItemListPage() {
168     if ("next".equals(pageDirection)) {
169       itemList.nextPage();
170     } else if ("previous".equals(pageDirection)) {
171       itemList.previousPage();
172     }
173     return "success";
174   }
175
176   public String JavaDoc viewItem() {
177     item = catalogService.getItem(itemId);
178     product = item.getProduct();
179     return "success";
180   }
181
182   public void clear () {
183     keyword = null;
184     pageDirection = null;
185
186     categoryId = null;
187     category = null;
188     categoryList = null;
189
190     productId = null;
191     product = null;
192     productList = null;
193
194     itemId = null;
195     item = null;
196     itemList = null;
197   }
198
199 }
200
Popular Tags