1 15 16 package com.jdon.strutsutil.taglib; 17 18 import javax.servlet.http.HttpServletRequest ; 19 import javax.servlet.jsp.JspException ; 20 21 import org.apache.struts.config.ModuleConfig; 22 import org.apache.struts.taglib.html.LinkTag; 23 24 import com.jdon.strutsutil.FormBeanUtil; 25 import com.jdon.strutsutil.ModelListForm; 26 import com.jdon.util.Debug; 27 35 public class MPageTag extends LinkTag { 36 37 private final static String module = MPageTag.class.getName(); 38 39 public final static String URLNAME = "URL"; 40 public final static String COUNT = "COUNT"; 41 public final static String START = "START"; 42 public final static String ALLCOUNT = "ALLCOUNT"; 43 public final static String NEXTPAGE = "NEXTPAGE"; 44 public final static String DISP = "DISP"; 45 46 private String actionFormName; 47 48 49 50 52 57 public int doStartTag() throws JspException { 58 59 ModuleConfig config = (ModuleConfig) pageContext.getRequest() 61 .getAttribute(org.apache.struts.Globals.MODULE_KEY); 62 63 HttpServletRequest request = 64 (HttpServletRequest ) pageContext.getRequest(); 65 String pageUrl = calculateURL(); 66 StringBuffer url = new StringBuffer (pageUrl); 67 if (pageUrl.indexOf("?") < 0) 68 url.append("?"); 69 else 70 url.append("&"); 71 72 73 74 ModelListForm form = null; 75 try { 76 form = (ModelListForm)FormBeanUtil.lookupActionForm((HttpServletRequest )pageContext.getRequest(), actionFormName); 77 if (form == null) throw new Exception (); 78 } catch (Exception e) { 79 Debug.logError("[JdonFramework]not found actionFormName value: " + actionFormName, module); 80 throw new JspException (" not found " + actionFormName); 81 } 82 83 int start = form.getStart(); 84 int allCount = form.getAllCount(); 85 int count = form.getCount(); 86 url.append("count=").append(count); 87 88 String nextPage = ""; 89 if ((allCount > (start + count)) ) 90 nextPage = NEXTPAGE; 91 92 pageContext.setAttribute(URLNAME, url.toString()); 93 pageContext.setAttribute(START, Integer.toString(start)); 94 pageContext.setAttribute(COUNT, Integer.toString(count)); 95 pageContext.setAttribute(ALLCOUNT, Integer.toString(allCount)); 96 pageContext.setAttribute(NEXTPAGE, nextPage); 97 98 int currentPage = 1; 99 if (count > 0 ){ 100 currentPage = (start / count) + 1; 101 } 102 103 if ((currentPage == 1) && (nextPage.length() == 0)){ 105 pageContext.setAttribute(DISP, "off"); }else 107 pageContext.setAttribute(DISP, "on"); 108 109 110 111 return (EVAL_BODY_INCLUDE); 113 114 } 115 116 121 public int doEndTag() throws JspException { 122 123 return (EVAL_PAGE); 124 125 } 126 127 130 public void release() { 131 132 super.release(); 133 134 135 } 136 public String getActionFormName() { 137 return actionFormName; 138 } 139 public void setActionFormName(String actionFormName) { 140 this.actionFormName = actionFormName; 141 } 142 143 } 144 | Popular Tags |