KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > servlet > http > jsp > tagext > iteration > PreviousPageTag


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.servlet.http.jsp.tagext.iteration;
8
9 import javax.servlet.jsp.JspException JavaDoc;
10 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
11
12 import org.apache.struts.util.RequestUtils;
13
14 /**
15  * Description of the Class
16  *
17  * @author Laurent Etiemble
18  * @version $Revision: 1.4 $
19  * @todo Javadoc to complete
20  * @jsp:tag name="previousPage"
21  * body-content="JSP"
22  */

23 public class PreviousPageTag extends BodyTagSupport JavaDoc
24 {
25    /** Description of the Field */
26    protected String JavaDoc current = null;
27    /** Description of the Field */
28    protected String JavaDoc length = null;
29    /** Description of the Field */
30    protected String JavaDoc scope = null;
31    /** Description of the Field */
32    protected String JavaDoc size = null;
33
34
35    /**
36     * Description of the Method
37     *
38     * @return Description of the Returned Value
39     * @exception JspException Description of Exception
40     */

41    public int doStartTag()
42       throws JspException JavaDoc
43    {
44       int currentPage = ((Integer JavaDoc) RequestUtils.lookup(pageContext, current, scope)).intValue();
45       int contentSize = ((Integer JavaDoc) RequestUtils.lookup(pageContext, size, scope)).intValue();
46       int pageLength = Integer.parseInt(length);
47
48       // Compute the last page
49
int lastPage = (contentSize / pageLength);
50       if ((contentSize % pageLength) > 0)
51       {
52          lastPage++;
53       }
54
55       if ((lastPage > 1) && (currentPage > 1))
56       {
57          return (EVAL_BODY_INCLUDE);
58       }
59       return (SKIP_BODY);
60    }
61
62
63    /**
64     * Returns the start.
65     *
66     * @return String
67     * @jsp:attribute name="current"
68     * required="true"
69     * rtexprvalue="true"
70     */

71    public String JavaDoc getCurrent()
72    {
73       return current;
74    }
75
76
77    /**
78     * Returns the page.
79     *
80     * @return String
81     * @jsp:attribute name="length"
82     * required="true"
83     * rtexprvalue="true"
84     */

85    public String JavaDoc getLength()
86    {
87       return length;
88    }
89
90
91    /**
92     * Getter for the scope attribute
93     *
94     * @return The value of scope attribute
95     * @jsp:attribute name="scope"
96     * required="false"
97     * rtexprvalue="true"
98     */

99    public String JavaDoc getScope()
100    {
101       return (this.scope);
102    }
103
104
105    /**
106     * Returns the length.
107     *
108     * @return String
109     * @jsp:attribute name="size"
110     * required="true"
111     * rtexprvalue="true"
112     */

113    public String JavaDoc getSize()
114    {
115       return size;
116    }
117
118
119    /** Release all allocated resources. */
120    public void release()
121    {
122       super.release();
123       size = null;
124       current = null;
125    }
126
127
128    /**
129     * Sets the current.
130     *
131     * @param current The current to set
132     */

133    public void setCurrent(String JavaDoc current)
134    {
135       this.current = current;
136    }
137
138
139    /**
140     * Sets the length.
141     *
142     * @param length The length to set
143     */

144    public void setLength(String JavaDoc length)
145    {
146       this.length = length;
147    }
148
149
150    /**
151     * Sets the scope.
152     *
153     * @param scope The scope to set
154     */

155    public void setScope(String JavaDoc scope)
156    {
157       this.scope = scope;
158    }
159
160
161    /**
162     * Sets the size.
163     *
164     * @param size The size to set
165     */

166    public void setSize(String JavaDoc size)
167    {
168       this.size = size;
169    }
170 }
171
172
Popular Tags