KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > pets > presentation > pages > SearchPage


1 package org.apache.tapestry.pets.presentation.pages;
2
3 import johnmammen.betterpetshop.service.PetshopManager;
4
5 import org.apache.commons.lang.StringUtils;
6 import org.apache.tapestry.IRequestCycle;
7 import org.apache.tapestry.event.PageEvent;
8 import org.apache.tapestry.event.PageRenderListener;
9 import org.apache.tapestry.pets.PetshopBasePage;
10 //import org.apache.tapestry.pets.actions.Products;
11
import org.apache.tapestry.pets.domain.model.IProduct;
12 import org.apache.tapestry.pets.presentation.components.PagedModel;
13
14
15 public abstract class SearchPage extends PetshopBasePage implements
16         PageRenderListener {
17
18     public static int PAGE_SIZE = 4;
19
20     private int currentPage;
21
22     private int pageCount;
23
24     //for getting the petshop service
25
public abstract PetshopManager getPetshopService();
26
27     public void pageBeginRender(PageEvent event) {
28         if (getModel() == null) setModel(new PagedModel());
29
30         if (StringUtils.isEmpty(getSearchWord())) {
31             setResults(false);
32             return;
33         }
34
35 // //
36
// PetshopManager petManager = null;
37
// try {
38
// WebApplicationContext appcontext = WebApplicationContextUtils
39
// .getWebApplicationContext(getRequestCycle()
40
// .getRequestContext().getServlet()
41
// .getServletContext());
42
// petManager = (PetshopManager) appcontext.getBean("petshopService");
43
// } catch (Exception e) {
44
//
45
// }
46

47
48         setSearchList(getPetshopService().findBySearchCriteria(getSearchWord()));
49
50         if (getSearchList() != null) {
51             // Initialize page properties.
52
// Initialization order matters.
53
getModel().setItemCount(getSearchList().length);
54             getModel()
55                     .setPageCount(
56                             (int) Math
57                                     .ceil(((double) getItemCount() / (double) getPageSize())));
58
59             setItemCount(getModel().getItemCount());
60             setPageCount(getModel().getPageCount());
61             setCurrentPage(getModel().getPageToShow());
62         }
63
64         if (getItemCount() == 0)
65             setResults(false);
66         else
67             setResults(true);
68     }
69
70     public void directJumpToPage(IRequestCycle cycle) {
71         Object JavaDoc[] parameters = cycle.getServiceParameters();
72         int page = ((Integer JavaDoc) parameters[0]).intValue();
73         int pCount = ((Integer JavaDoc) parameters[1]).intValue();
74         String JavaDoc nsearchWord = ((String JavaDoc) parameters[2]);
75         PagedModel nmodel = new PagedModel();
76         nmodel.setPageCount(pCount);
77         nmodel.setPageToShow(page);
78         setModel(nmodel);
79         setSearchWord(nsearchWord);
80     }
81
82     public void selectItem(IRequestCycle cycle) {
83         Object JavaDoc[] parameters = cycle.getServiceParameters();
84         String JavaDoc prodid = ((String JavaDoc) parameters[0]);
85         String JavaDoc prodname = ((String JavaDoc) parameters[1]);
86         ProductCategoryPage productcategory = (ProductCategoryPage) cycle
87                 .getPage("ProductCategory");
88         productcategory.setProdID(prodid);
89         productcategory.setProdName(prodname);
90         cycle.activate(productcategory);
91     }
92
93     public abstract int getItemCount();
94
95     public abstract int getCurrentPage();
96
97     public abstract int getPageCount();
98
99     public abstract PagedModel getModel();
100
101     public abstract int getPageSize();
102
103     public abstract boolean isResults();
104
105     public abstract IProduct getSearchItem();
106
107     public abstract IProduct[] getSearchList();
108
109     public abstract String JavaDoc getSearchWord();
110
111     public abstract void setItemCount(int i);
112
113     public abstract void setModel(PagedModel model);
114
115     public abstract void setPageSize(int i);
116
117     public abstract void setResults(boolean b);
118
119     public abstract void setSearchItem(IProduct product);
120
121     public abstract void setSearchList(IProduct[] products);
122
123     public abstract void setSearchWord(String JavaDoc string);
124
125     public abstract void setCurrentPage(int i);
126
127     public abstract void setPageCount(int i);
128
129 }
Popular Tags