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 private static final long serialVersionUID = 5849523372175050635L;
39
40 private static final String MAIN = "/WEB-INF/jsp/catalog/Main.jsp";
41 private static final String VIEW_CATEGORY = "/WEB-INF/jsp/catalog/Category.jsp";
42 private static final String VIEW_PRODUCT = "/WEB-INF/jsp/catalog/Product.jsp";
43 private static final String VIEW_ITEM = "/WEB-INF/jsp/catalog/Item.jsp";
44 private static final String SEARCH_PRODUCTS = "/WEB-INF/jsp/catalog/SearchProducts.jsp";
45
46 @SpringBean
47 private transient CatalogService catalogService;
48
49 private String keyword;
50
51 private String categoryId;
52 private Category category;
53 private List<Category> categoryList;
54
55 private String productId;
56 private Product product;
57 private List<Product> productList;
58
59 private String itemId;
60 private Item item;
61 private List<Item> itemList;
62
63 public String getKeyword() {
64 return keyword;
65 }
66
67 public void setKeyword(String keyword) {
68 this.keyword = keyword;
69 }
70
71 public String getCategoryId() {
72 return categoryId;
73 }
74
75 public void setCategoryId(String categoryId) {
76 this.categoryId = categoryId;
77 }
78
79 public String getProductId() {
80 return productId;
81 }
82
83 public void setProductId(String productId) {
84 this.productId = productId;
85 }
86
87 public String getItemId() {
88 return itemId;
89 }
90
91 public void setItemId(String itemId) {
92 this.itemId = itemId;
93 }
94
95 public Category getCategory() {
96 return category;
97 }
98
99 public void setCategory(Category category) {
100 this.category = category;
101 }
102
103 public Product getProduct() {
104 return product;
105 }
106
107 public void setProduct(Product product) {
108 this.product = product;
109 }
110
111 public Item getItem() {
112 return item;
113 }
114
115 public void setItem(Item item) {
116 this.item = item;
117 }
118
119 public List<Category> getCategoryList() {
120 return categoryList;
121 }
122
123 public void setCategoryList(List<Category> categoryList) {
124 this.categoryList = categoryList;
125 }
126
127 public List<Product> getProductList() {
128 return productList;
129 }
130
131 public void setProductList(List<Product> productList) {
132 this.productList = productList;
133 }
134
135 public List<Item> getItemList() {
136 return itemList;
137 }
138
139 public void setItemList(List<Item> itemList) {
140 this.itemList = itemList;
141 }
142
143 @DefaultHandler
144 public ForwardResolution viewMain() {
145 return new ForwardResolution(MAIN);
146 }
147
148
149
150
151
152
153 public ForwardResolution viewCategory() {
154 if (categoryId != null) {
155 productList = catalogService.getProductListByCategory(categoryId);
156 category = catalogService.getCategory(categoryId);
157 }
158 return new ForwardResolution(VIEW_CATEGORY);
159 }
160
161
162
163
164
165
166 public ForwardResolution viewProduct() {
167 if (productId != null) {
168 itemList = catalogService.getItemListByProduct(productId);
169 product = catalogService.getProduct(productId);
170 }
171 return new ForwardResolution(VIEW_PRODUCT);
172 }
173
174
175
176
177
178
179 public ForwardResolution viewItem() {
180 item = catalogService.getItem(itemId);
181 product = item.getProduct();
182 return new ForwardResolution(VIEW_ITEM);
183 }
184
185
186
187
188
189
190 public ForwardResolution searchProducts() {
191 if (keyword == null || keyword.length() < 1) {
192 setMessage("Please enter a keyword to search for, then press the search button.");
193 return new ForwardResolution(ERROR);
194 } else {
195 productList = catalogService.searchProductList(keyword.toLowerCase());
196 return new ForwardResolution(SEARCH_PRODUCTS);
197 }
198 }
199
200
201
202
203 public void clear() {
204 keyword = null;
205
206 categoryId = null;
207 category = null;
208 categoryList = null;
209
210 productId = null;
211 product = null;
212 productList = null;
213
214 itemId = null;
215 item = null;
216 itemList = null;
217 }
218
219 }