KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > taglib > core > grid > NextPageTag


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

16 package com.blandware.atleap.webapp.taglib.core.grid;
17
18 import com.blandware.atleap.webapp.taglib.core.BaseHandlerTag;
19 import com.blandware.atleap.webapp.util.core.RequestUtil;
20 import org.apache.struts.taglib.TagUtils;
21
22 import javax.servlet.jsp.JspException JavaDoc;
23 import javax.servlet.jsp.JspTagException JavaDoc;
24 import javax.servlet.jsp.PageContext JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.StringWriter JavaDoc;
27 import java.util.Map JavaDoc;
28
29
30 /**
31  * <p>This tag renders to hyperlink to next page if it exists.
32  * Body of link will be the body of this tag.
33  * <br />
34  * This tag is only valid when nested within <em>pager</em> tag.
35  * </p>
36  * <p><a HREF="NextPageTag.java.htm"><i>View Source</i></a></p>
37  *
38  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
39  * @version $Revision: 1.9 $ $Date: 2005/09/21 13:45:59 $
40  * @see FirstPageTag
41  * @see PrevPageTag
42  * @see LastPageTag
43  * @jsp.tag name="nextPage"
44  * body-content="scriptless"
45  * @see com.blandware.atleap.webapp.taglib.core.grid.PagerTag
46  */

47 public class NextPageTag extends BaseHandlerTag {
48
49     /**
50      * Processes the tag
51      *
52      * @throws JspException
53      * @throws IOException
54      */

55     public void doTag() throws JspException JavaDoc, IOException JavaDoc {
56
57         PageContext JavaDoc pageContext = (PageContext JavaDoc) getJspContext();
58
59         // This tag is only valid when nested within 'pager' tag, so check this
60
PagerTag parentPagerTag = (PagerTag) findAncestorWithClass(this, PagerTag.class);
61
62         if ( parentPagerTag == null ) {
63             JspTagException JavaDoc e = new JspTagException JavaDoc("Parent tag is invalid! This tag is only valid when nested within 'pager' tag");
64             throw e;
65         }
66
67         GridTag parentGridTag = (GridTag) findAncestorWithClass(this, GridTag.class);
68
69         int currentPageNumber = parentGridTag.getCurrentPageNumber().intValue();
70         int lastPageNumber = parentPagerTag.getLastPageNumber().intValue();
71
72         // If there are no pages after current, skip body, otherwise create a hyperlink
73

74         if ( currentPageNumber < lastPageNumber ) {
75
76             String JavaDoc pageUrl = parentGridTag.getPageUrl();
77
78             Map JavaDoc parameterMap = RequestUtil.prepareParameterMap(parentGridTag.getParameterMap());
79             parameterMap.put("pageNumber", String.valueOf(currentPageNumber + 1));
80             parameterMap.put("gridName", parentGridTag.getName());
81             pageUrl += "?" + RequestUtil.createQueryStringFromMap(parameterMap, "&");
82
83             StringWriter JavaDoc sw = new StringWriter JavaDoc();
84             StringBuffer JavaDoc sb = sw.getBuffer();
85             sb.append("<a HREF=\"").append(pageUrl).append("\"").append(prepareAttributes()).append(">");
86             getJspBody().invoke(sw);
87             sb.append("</a>");
88             TagUtils.getInstance().write(pageContext, sw.toString());
89         }
90     }
91
92 }
93
Popular Tags