001: package com.ibatis.jpetstore.presentation;
002:
003: import org.huihoo.jfox.soaf.container.ServiceFactory;
004:
005: import com.ibatis.common.util.PaginatedList;
006: import com.ibatis.jpetstore.domain.Category;
007: import com.ibatis.jpetstore.domain.Item;
008: import com.ibatis.jpetstore.domain.Product;
009: import com.ibatis.jpetstore.service.CatalogService;
010: import com.ibatis.struts.ActionContext;
011: import com.ibatis.struts.BaseBean;
012:
013: /**
014: * <p/>Date: Mar 9, 2004 10:16:59 PM
015: *
016: * @author Clinton Begin
017: */
018: public class CatalogBean extends BaseBean {
019:
020: /* Constants */
021:
022: private CatalogService catalogService = (CatalogService) ServiceFactory
023: .getInstance().getService(CatalogService.class);
024:
025: /* Private Fields */
026:
027: private String keyword;
028:
029: private String pageDirection;
030:
031: private String categoryId;
032:
033: private Category category;
034:
035: private PaginatedList categoryList;
036:
037: private String productId;
038:
039: private Product product;
040:
041: private PaginatedList productList;
042:
043: private String itemId;
044:
045: private Item item;
046:
047: private PaginatedList itemList;
048:
049: /* JavaBeans Properties */
050:
051: public String getKeyword() {
052: return keyword;
053: }
054:
055: public void setKeyword(String keyword) {
056: this .keyword = keyword;
057: }
058:
059: public String getPageDirection() {
060: return pageDirection;
061: }
062:
063: public void setPageDirection(String pageDirection) {
064: this .pageDirection = pageDirection;
065: }
066:
067: public String getCategoryId() {
068: return categoryId;
069: }
070:
071: public void setCategoryId(String categoryId) {
072: this .categoryId = categoryId;
073: }
074:
075: public String getProductId() {
076: return productId;
077: }
078:
079: public void setProductId(String productId) {
080: this .productId = productId;
081: }
082:
083: public String getItemId() {
084: return itemId;
085: }
086:
087: public void setItemId(String itemId) {
088: this .itemId = itemId;
089: }
090:
091: public Category getCategory() {
092: return category;
093: }
094:
095: public void setCategory(Category category) {
096: this .category = category;
097: }
098:
099: public Product getProduct() {
100: return product;
101: }
102:
103: public void setProduct(Product product) {
104: this .product = product;
105: }
106:
107: public Item getItem() {
108: return item;
109: }
110:
111: public void setItem(Item item) {
112: this .item = item;
113: }
114:
115: public PaginatedList getCategoryList() {
116: return categoryList;
117: }
118:
119: public void setCategoryList(PaginatedList categoryList) {
120: this .categoryList = categoryList;
121: }
122:
123: public PaginatedList getProductList() {
124: return productList;
125: }
126:
127: public void setProductList(PaginatedList productList) {
128: this .productList = productList;
129: }
130:
131: public PaginatedList getItemList() {
132: return itemList;
133: }
134:
135: public void setItemList(PaginatedList itemList) {
136: this .itemList = itemList;
137: }
138:
139: /* Public Methods */
140:
141: public String viewCategory() {
142: if (categoryId != null) {
143: productList = catalogService
144: .getProductListByCategory(categoryId);
145: category = catalogService.getCategory(categoryId);
146: }
147: return "success";
148: }
149:
150: public String searchProducts() {
151: if (keyword == null || keyword.length() < 1) {
152: ActionContext
153: .getActionContext()
154: .setSimpleMessage(
155: "Please enter a keyword to search for, then press the search button.");
156: return "failure";
157: } else {
158: productList = catalogService.searchProductList(keyword
159: .toLowerCase());
160: return "success";
161: }
162: }
163:
164: public String switchProductListPage() {
165: if ("next".equals(pageDirection)) {
166: productList.nextPage();
167: } else if ("previous".equals(pageDirection)) {
168: productList.previousPage();
169: }
170: return "success";
171: }
172:
173: public String viewProduct() {
174: if (productId != null) {
175: itemList = catalogService.getItemListByProduct(productId);
176: product = catalogService.getProduct(productId);
177: }
178: return "success";
179: }
180:
181: public String switchItemListPage() {
182: if ("next".equals(pageDirection)) {
183: itemList.nextPage();
184: } else if ("previous".equals(pageDirection)) {
185: itemList.previousPage();
186: }
187: return "success";
188: }
189:
190: public String viewItem() {
191: item = catalogService.getItem(itemId);
192: product = item.getProduct();
193: return "success";
194: }
195:
196: public void clear() {
197: keyword = null;
198: pageDirection = null;
199:
200: categoryId = null;
201: category = null;
202: categoryList = null;
203:
204: productId = null;
205: product = null;
206: productList = null;
207:
208: itemId = null;
209: item = null;
210: itemList = null;
211: }
212:
213: }
|