1 16 package com.blandware.atleap.webapp.taglib.core.grid; 17 18 import org.apache.commons.logging.Log; 19 import org.apache.commons.logging.LogFactory; 20 21 import javax.servlet.jsp.JspException ; 22 import javax.servlet.jsp.JspTagException ; 23 import javax.servlet.jsp.PageContext ; 24 import javax.servlet.jsp.tagext.JspFragment ; 25 import javax.servlet.jsp.tagext.SimpleTagSupport ; 26 import java.io.IOException ; 27 28 73 public class PagerTag extends SimpleTagSupport { 74 75 protected transient final Log log = LogFactory.getLog(PagerTag.class); 76 77 80 protected Integer pageCount = null; 81 82 85 protected Integer lastPageNumber = null; 86 87 96 public Integer getPageCount() { 97 return pageCount; 98 } 99 100 105 public void setPageCount(Integer pageCount) { 106 this.pageCount = pageCount; 107 } 108 109 114 protected Integer getLastPageNumber() { 115 return this.lastPageNumber; 116 } 117 118 124 public void doTag() throws JspException , IOException { 125 126 PageContext pageContext = (PageContext ) getJspContext(); 127 128 GridTag parentGridTag = (GridTag) findAncestorWithClass(this, GridTag.class); 130 131 if ( parentGridTag == null ) { 132 JspTagException e = new JspTagException ("Parent tag is invalid! This tag is only valid when nested within 'grid' tag"); 133 throw e; 134 } 135 136 138 if ( pageCount == null ) { 139 pageCount = new Integer (10); 140 } 141 142 int total = parentGridTag.getGrid().getTotal().intValue(); 143 int pageSize = parentGridTag.getPageSize().intValue(); 144 if (pageSize <= 0) { 145 throw new IllegalArgumentException ("Page size must be positive"); 146 } 147 148 if ( total > pageSize ) { 149 150 int last = total / pageSize; 151 if ( total % pageSize > 0 ) { 152 last += 1; 153 } 154 155 if ( last <= 1 ) { 156 last = 1; 157 } 158 159 lastPageNumber = new Integer (last); 160 161 JspFragment body = getJspBody(); 162 if ( body != null ) { 163 body.invoke(null); 164 } 165 } 166 } 167 168 } 169 | Popular Tags |