1 7 package org.ejtools.servlet.http.jsp.tagext.iteration; 8 9 import javax.servlet.jsp.JspException ; 10 import javax.servlet.jsp.tagext.TagSupport ; 11 12 import org.apache.struts.util.RequestUtils; 13 14 23 public class ComputePageTag extends TagSupport 24 { 25 26 protected String current = null; 27 28 protected String id = null; 29 30 protected String length = null; 31 32 protected String offset = null; 33 34 protected String scope = null; 35 36 protected String size = null; 37 38 39 45 public int doStartTag() 46 throws JspException 47 { 48 int currentPage = ((Integer ) RequestUtils.lookup(pageContext, current, scope)).intValue(); 49 int contentSize = ((Integer ) RequestUtils.lookup(pageContext, size, scope)).intValue(); 50 int offsetValue = Integer.parseInt(offset); 51 int pageLength = Integer.parseInt(length); 52 53 int lastPage = (contentSize / pageLength); 55 if ((contentSize % pageLength) > 0) 56 { 57 lastPage++; 58 } 59 if (lastPage == 0) 60 { 61 lastPage = 1; 62 } 63 if (currentPage < 1) 64 { 65 currentPage = 1; 66 } 67 if (currentPage > lastPage) 68 { 69 currentPage = 1; 70 } 71 72 currentPage = currentPage + offsetValue; 74 75 int index = (currentPage - 1) * pageLength; 76 77 pageContext.setAttribute(current, new Integer (currentPage)); 78 pageContext.setAttribute(id, new Integer (index)); 79 80 return (SKIP_BODY); 82 } 83 84 85 93 public String getCurrent() 94 { 95 return current; 96 } 97 98 99 107 public String getId() 108 { 109 return id; 110 } 111 112 113 121 public String getLength() 122 { 123 return length; 124 } 125 126 127 135 public String getOffset() 136 { 137 return offset; 138 } 139 140 141 149 public String getScope() 150 { 151 return (this.scope); 152 } 153 154 155 163 public String getSize() 164 { 165 return size; 166 } 167 168 169 170 public void release() 171 { 172 super.release(); 173 size = null; 174 current = null; 175 } 176 177 178 183 public void setCurrent(String current) 184 { 185 this.current = current; 186 } 187 188 189 194 public void setId(String id) 195 { 196 this.id = id; 197 } 198 199 200 205 public void setLength(String length) 206 { 207 this.length = length; 208 } 209 210 211 216 public void setOffset(String offset) 217 { 218 this.offset = offset; 219 } 220 221 222 227 public void setScope(String scope) 228 { 229 this.scope = scope; 230 } 231 232 233 238 public void setSize(String size) 239 { 240 this.size = size; 241 } 242 } 243 244 | Popular Tags |