KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.servlet.jsp.JspException JavaDoc;
19 import javax.servlet.jsp.JspTagException JavaDoc;
20 import javax.servlet.jsp.PageContext JavaDoc;
21 import javax.servlet.jsp.tagext.JspFragment JavaDoc;
22 import javax.servlet.jsp.tagext.SimpleTagSupport JavaDoc;
23 import java.io.IOException JavaDoc;
24
25 /**
26  * <p>Body of this tag will be rendered if and only if page number
27  * (in pagesIterator) is equal to number of page that is currently displayed
28  * (in grid).
29  * <br />
30  * This tag is only valid when nested within <em>pagesIterator</em> tag.
31  * </p>
32  * <p><a HREF="CurrentPageTag.java.htm"><i>View Source</i></a></p>
33  *
34  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
35  * @version $Revision: 1.7 $ $Date: 2005/09/21 13:45:59 $
36  * @see PagerTag
37  * @see PageTag
38  * @jsp.tag name="currentPage"
39  * body-content="scriptless"
40  * @see com.blandware.atleap.webapp.taglib.core.grid.PagesIteratorTag
41  */

42 public class CurrentPageTag extends SimpleTagSupport JavaDoc {
43
44     /**
45      * Processes the tag
46      *
47      * @throws JspException
48      * @throws IOException
49      */

50     public void doTag() throws JspException JavaDoc, IOException JavaDoc {
51
52         PageContext JavaDoc pageContext = (PageContext JavaDoc) getJspContext();
53
54         // This tag is only valid when nested within 'pagesIterator' tag, so check this
55
PagesIteratorTag parentPagesIteratorTag = (PagesIteratorTag) findAncestorWithClass(this, PagesIteratorTag.class);
56
57         if ( parentPagesIteratorTag == null ) {
58             JspTagException JavaDoc e = new JspTagException JavaDoc("Parent tag is invalid! This tag is only valid when nested within 'pagesIterator' tag");
59             throw e;
60         }
61
62         GridTag parentGridTag = (GridTag) findAncestorWithClass(this, GridTag.class);
63
64         // Render body if page iteration counter in pagesIterator tag is equal to current page
65
// displayed in grid
66

67         Integer JavaDoc pageNumber = parentPagesIteratorTag.getPageNumber();
68
69         if ( parentGridTag.getCurrentPageNumber().equals(pageNumber) ) {
70             JspFragment JavaDoc body = getJspBody();
71             if ( body != null ) {
72                 body.invoke(null);
73             }
74         }
75
76     }
77
78 }
79
Popular Tags