KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jdon > strutsutil > taglib > MPageTag


1 /**
2  * Copyright 2003-2006 the original author or authors.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6
7        http://www.apache.org/licenses/LICENSE-2.0
8
9   * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */

15
16 package com.jdon.strutsutil.taglib;
17
18 import javax.servlet.http.HttpServletRequest JavaDoc;
19 import javax.servlet.jsp.JspException JavaDoc;
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 /**
28  * 类似Html:link
29  *
30  * <p>Copyright: Jdon.com Copyright (c) 2003</p>
31  * <p></p>
32  * @author banq
33  * @version 1.0
34  */

35 public class MPageTag extends LinkTag {
36
37   private final static String JavaDoc module = MPageTag.class.getName();
38
39   public final static String JavaDoc URLNAME = "URL";
40   public final static String JavaDoc COUNT = "COUNT";
41   public final static String JavaDoc START = "START";
42   public final static String JavaDoc ALLCOUNT = "ALLCOUNT";
43   public final static String JavaDoc NEXTPAGE = "NEXTPAGE";
44   public final static String JavaDoc DISP = "DISP";
45
46   private String JavaDoc actionFormName;
47
48
49
50   // --------------------------------------------------------- Public Methods
51

52   /**
53    * Render the beginning of the hyperlink.
54    *
55    * @exception JspException if a JSP exception has occurred
56    */

57   public int doStartTag() throws JspException JavaDoc {
58
59     // Generate the URL to be encoded
60
ModuleConfig config = (ModuleConfig) pageContext.getRequest()
61         .getAttribute(org.apache.struts.Globals.MODULE_KEY);
62
63     HttpServletRequest JavaDoc request =
64         (HttpServletRequest JavaDoc) pageContext.getRequest();
65     String JavaDoc pageUrl = calculateURL();
66     StringBuffer JavaDoc url = new StringBuffer JavaDoc(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 JavaDoc)pageContext.getRequest(), actionFormName);
77       if (form == null) throw new Exception JavaDoc();
78     } catch (Exception JavaDoc e) {
79       Debug.logError("[JdonFramework]not found actionFormName value: " + actionFormName, module);
80       throw new JspException JavaDoc(" 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 JavaDoc 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     //当å‰?å?ªæœ‰ä¸€é¡µï¼Œæ²¡æœ‰ä¸‹ä¸€é¡µ
104
if ((currentPage == 1) && (nextPage.length() == 0)){
105       pageContext.setAttribute(DISP, "off"); //ä¸?显示其它标识
106
}else
107       pageContext.setAttribute(DISP, "on");
108
109
110
111     // Evaluate the body of this tag
112
return (EVAL_BODY_INCLUDE);
113
114   }
115
116   /**
117    * Render the end of the hyperlink.
118    *
119    * @exception JspException if a JSP exception has occurred
120    */

121   public int doEndTag() throws JspException JavaDoc {
122
123     return (EVAL_PAGE);
124
125   }
126
127   /**
128    * Release any acquired resources.
129    */

130   public void release() {
131
132     super.release();
133
134
135   }
136   public String JavaDoc getActionFormName() {
137     return actionFormName;
138   }
139   public void setActionFormName(String JavaDoc actionFormName) {
140     this.actionFormName = actionFormName;
141   }
142
143 }
144
Popular Tags