1 5 package org.exoplatform.faces.core.component; 6 7 import java.util.Map ; 8 import java.util.List ; 9 import javax.faces.context.FacesContext; 10 import org.exoplatform.commons.utils.PageList; 11 import org.exoplatform.faces.core.component.model.PageListDataHandler; 12 18 public class UIPageListIterator extends UIExoComponentBase { 19 public static final String COMPONENT_FAMILY = "org.exoplatform.faces.core.component.UIPageListIterator" ; 20 public static final String PAGE_PARAM = "page" ; 21 private String cache_ ; 22 private PageListDataHandler dataHandler_ ; 23 24 public UIPageListIterator(PageListDataHandler dataHandler) { 25 dataHandler_ = dataHandler ; 26 cache_ = null ; 27 setClazz("UIPageIterator") ; 28 setId("UIPageListIterator"); 29 setRendererType("PageListIteratorRenderer") ; 30 setRendered(true); 31 } 32 33 public int getAvailablePage() { return dataHandler_.getAvailablePage() ; } 34 35 public int getCurrentPage() { return dataHandler_.getCurrentPage() ; } 36 37 public int getAvailable() { return dataHandler_.getAvailable() ; } 38 39 public int getFrom() { return dataHandler_.getFrom() ; } 40 public int getTo() { return dataHandler_.getTo() ; } 41 42 public String getCache() { return cache_ ; } 43 public void setCache(String cache) { cache_ = cache ; } 44 45 46 public PageListDataHandler getPageListDataHandler() { return dataHandler_ ; } 47 public void setPageListDataHandler(PageListDataHandler dh) { 48 dataHandler_ = dh; 49 cache_ = null ; 50 } 51 52 public void setPageList(PageList l) throws Exception { 53 dataHandler_.setPageList(l) ; 54 cache_ = null ; 55 } 56 57 public List getObjectInCurrentPage() { 58 return dataHandler_.getObjectInCurrentPage() ; 59 } 60 61 public String getFamily() { return COMPONENT_FAMILY ; } 62 63 public Object getObjectInPage(int index) throws Exception { 64 return dataHandler_.getObjectInPage(index) ; 65 } 66 67 public void decode(FacesContext context) { 68 Map paramMap = context.getExternalContext().getRequestParameterMap() ; 69 String comp = (String ) paramMap.get(UICOMPONENT) ; 70 if(getId().equals(comp)) { 71 try{ 72 String page = (String ) paramMap.get(PAGE_PARAM) ; 73 int selectPage = Integer.parseInt(page) ; 74 dataHandler_.selectPage(selectPage) ; 75 cache_ = null ; 76 context.renderResponse() ; 77 } catch (Exception ex) { 78 ex.printStackTrace() ; 79 } 80 } 81 } 82 } | Popular Tags |