1 package org.apache.tapestry.pets.presentation.pages; 2 3 import java.text.NumberFormat ; 4 5 6 import johnmammen.betterpetshop.service.PetshopManager; 7 8 import org.apache.commons.lang.StringUtils; 9 import org.apache.tapestry.IRequestCycle; 10 import org.apache.tapestry.event.PageEvent; 11 import org.apache.tapestry.event.PageRenderListener; 12 import org.apache.tapestry.pets.PetshopBasePage; 13 14 import org.apache.tapestry.pets.domain.model.IItem; 15 import org.apache.tapestry.pets.presentation.components.PagedModel; 16 17 18 public abstract class ProductCategoryPage extends PetshopBasePage implements 19 PageRenderListener { 20 public abstract PetshopManager getPetshopService(); 22 23 public void pageBeginRender(PageEvent event) { 24 25 if (getProdID() != null) 26 setItemsList(getPetshopService().getItemsByProduct(getProdID())); 27 28 if (getModel() == null) setModel(new PagedModel()); 29 30 if (getCurrencyFormat() == null) 31 setCurrencyFormat(NumberFormat.getCurrencyInstance(getEngine() 32 .getLocale())); 33 } 34 35 public abstract void setProdID(String prodid_value); 36 37 public abstract String getProdID(); 38 39 public abstract void setProdName(String prodname_value); 40 41 public abstract String getProdName(); 42 43 public abstract void setItemsList(IItem[] iList); 44 45 public abstract IItem[] getItemsList(); 46 47 public abstract IItem getCurrentItem(); 48 49 public abstract void setCurrentItem(IItem value); 50 51 public abstract NumberFormat getCurrencyFormat(); 52 53 public abstract void setCurrencyFormat(NumberFormat format); 54 55 public abstract PagedModel getModel(); 56 57 public abstract void setModel(PagedModel model); 58 59 public int getCurrentPage() { 60 return getModel().getPageToShow(); 61 } 62 63 public int getPageCount() { 64 return getModel().getPageCount(); 65 } 66 67 public void directJumpToPage(IRequestCycle cycle) { 68 Object [] parameters = cycle.getServiceParameters(); 69 int page = ((Integer ) parameters[0]).intValue(); 70 int pCount = ((Integer ) parameters[1]).intValue(); 71 String [] state = StringUtils.split((String ) parameters[2], "#"); 72 73 PagedModel nmodel = new PagedModel(); 74 nmodel.setPageCount(pCount); 75 nmodel.setPageToShow(page); 76 setModel(nmodel); 77 setProdID(state[0]); 78 setProdName(state[1]); 79 } 80 81 public void directShowItemDetails(IRequestCycle cycle) { 82 Object [] parameters = cycle.getServiceParameters(); 83 ProductDetailsPage prodDetails = (ProductDetailsPage) cycle 84 .getPage("ProductDetails"); 85 prodDetails.setItemID(((String ) parameters[0])); 86 cycle.activate(prodDetails); 87 } 88 89 } | Popular Tags |