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