1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.mybatis.jpetstore.web.actions;
17
18 import java.util.List;
19
20 import net.sourceforge.stripes.action.DefaultHandler;
21 import net.sourceforge.stripes.action.ForwardResolution;
22 import net.sourceforge.stripes.action.SessionScope;
23 import net.sourceforge.stripes.integration.spring.SpringBean;
24
25 import org.mybatis.jpetstore.domain.Category;
26 import org.mybatis.jpetstore.domain.Item;
27 import org.mybatis.jpetstore.domain.Product;
28 import org.mybatis.jpetstore.service.CatalogService;
29
30
31
32
33
34
35 @SessionScope
36 public class CatalogActionBean extends AbstractActionBean {
37
38
39 private static final long serialVersionUID = 5849523372175050635L;
40
41
42 private static final String MAIN = "/WEB-INF/jsp/catalog/Main.jsp";
43
44 private static final String VIEW_CATEGORY = "/WEB-INF/jsp/catalog/Category.jsp";
45
46 private static final String VIEW_PRODUCT = "/WEB-INF/jsp/catalog/Product.jsp";
47
48 private static final String VIEW_ITEM = "/WEB-INF/jsp/catalog/Item.jsp";
49
50 private static final String SEARCH_PRODUCTS = "/WEB-INF/jsp/catalog/SearchProducts.jsp";
51
52
53 @SpringBean
54 private transient CatalogService catalogService;
55
56
57 private String keyword;
58
59
60 private String categoryId;
61
62 private Category category;
63
64 private List<Category> categoryList;
65
66
67 private String productId;
68
69 private Product product;
70
71 private List<Product> productList;
72
73
74 private String itemId;
75
76 private Item item;
77
78 private List<Item> itemList;
79
80
81
82
83
84
85 public String getKeyword() {
86 return keyword;
87 }
88
89
90
91
92
93
94
95 public void setKeyword(String keyword) {
96 this.keyword = keyword;
97 }
98
99
100
101
102
103
104 public String getCategoryId() {
105 return categoryId;
106 }
107
108
109
110
111
112
113
114 public void setCategoryId(String categoryId) {
115 this.categoryId = categoryId;
116 }
117
118
119
120
121
122
123 public String getProductId() {
124 return productId;
125 }
126
127
128
129
130
131
132
133 public void setProductId(String productId) {
134 this.productId = productId;
135 }
136
137
138
139
140
141
142 public String getItemId() {
143 return itemId;
144 }
145
146
147
148
149
150
151
152 public void setItemId(String itemId) {
153 this.itemId = itemId;
154 }
155
156
157
158
159
160
161 public Category getCategory() {
162 return category;
163 }
164
165
166
167
168
169
170
171 public void setCategory(Category category) {
172 this.category = category;
173 }
174
175
176
177
178
179
180 public Product getProduct() {
181 return product;
182 }
183
184
185
186
187
188
189
190 public void setProduct(Product product) {
191 this.product = product;
192 }
193
194
195
196
197
198
199 public Item getItem() {
200 return item;
201 }
202
203
204
205
206
207
208
209 public void setItem(Item item) {
210 this.item = item;
211 }
212
213
214
215
216
217
218 public List<Category> getCategoryList() {
219 return categoryList;
220 }
221
222
223
224
225
226
227
228 public void setCategoryList(List<Category> categoryList) {
229 this.categoryList = categoryList;
230 }
231
232
233
234
235
236
237 public List<Product> getProductList() {
238 return productList;
239 }
240
241
242
243
244
245
246
247 public void setProductList(List<Product> productList) {
248 this.productList = productList;
249 }
250
251
252
253
254
255
256 public List<Item> getItemList() {
257 return itemList;
258 }
259
260
261
262
263
264
265
266 public void setItemList(List<Item> itemList) {
267 this.itemList = itemList;
268 }
269
270
271
272
273
274
275 @DefaultHandler
276 public ForwardResolution viewMain() {
277 return new ForwardResolution(MAIN);
278 }
279
280
281
282
283
284
285 public ForwardResolution viewCategory() {
286 if (categoryId != null) {
287 productList = catalogService.getProductListByCategory(categoryId);
288 category = catalogService.getCategory(categoryId);
289 }
290 return new ForwardResolution(VIEW_CATEGORY);
291 }
292
293
294
295
296
297
298 public ForwardResolution viewProduct() {
299 if (productId != null) {
300 itemList = catalogService.getItemListByProduct(productId);
301 product = catalogService.getProduct(productId);
302 }
303 return new ForwardResolution(VIEW_PRODUCT);
304 }
305
306
307
308
309
310
311 public ForwardResolution viewItem() {
312 item = catalogService.getItem(itemId);
313 product = item.getProduct();
314 return new ForwardResolution(VIEW_ITEM);
315 }
316
317
318
319
320
321
322 public ForwardResolution searchProducts() {
323 if (keyword == null || keyword.length() < 1) {
324 setMessage("Please enter a keyword to search for, then press the search button.");
325 return new ForwardResolution(ERROR);
326 } else {
327 productList = catalogService.searchProductList(keyword.toLowerCase());
328 return new ForwardResolution(SEARCH_PRODUCTS);
329 }
330 }
331
332
333
334
335 public void clear() {
336 keyword = null;
337
338 categoryId = null;
339 category = null;
340 categoryList = null;
341
342 productId = null;
343 product = null;
344 productList = null;
345
346 itemId = null;
347 item = null;
348 itemList = null;
349 }
350
351 }