KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > dbtags > resultset > RowCountTag


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
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 org.apache.taglibs.dbtags.resultset;
17
18 import java.io.IOException JavaDoc;
19
20 import javax.servlet.jsp.JspTagException JavaDoc;
21 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
22
23 /**
24  * <p>Prints out the number of rows retrieved from the database.
25  * It can be used inside a ResultSet tag to provide a running
26  * count of rows retreived, or after the ResultSet tag to
27  * display the total number. Using the tag before the ResultSet
28  * will
29  * produce an error.</p>
30  *
31  * <p>JSP Tag Lib Descriptor
32  * <pre>
33  * &lt;name>rowCount&lt;/name>
34  * &lt;tagclass>org.apache.taglibs.dbtags.statement.RowCountTag&lt;/tagclass>
35  * &lt;bodycontent>empty&lt;/bodycontent>
36  * &lt;info>Prints out the number of rows retrieved from the database.
37  * It can be used inside a ResultSet tag to provide a running
38  * count of rows retreived, or after the ResultSet tag to
39  * display the total number. Using the tag before the ResultSet
40  * will
41  * produce an error.&lt;/info>
42  * </pre>
43  *
44  * @author Morgan Delagrange
45  */

46 public class RowCountTag extends TagSupport JavaDoc {
47
48   public int doStartTag() throws JspTagException JavaDoc {
49
50     Integer JavaDoc integer =
51       (Integer JavaDoc) pageContext.getAttribute("org.apache.taglibs.dbtags.resultset.rowcount");
52
53     if (integer == null) {
54       throw new JspTagException JavaDoc("rowCount tag must be used inside or after a ResultSet tag.");
55     }
56
57     try {
58       pageContext.getOut().write(integer.toString());
59     } catch (IOException JavaDoc e) {
60       throw new JspTagException JavaDoc(e.toString());
61     }
62
63     return SKIP_BODY;
64   }
65
66 }
67
Popular Tags