View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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    /* Constants */
36  
37    private static final CatalogService catalogService = CatalogService.getInstance();
38  
39    /* Private Fields */
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    /* JavaBeans Properties */
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   /* Public Methods */
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 }