KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > examples > taglib > OddTag


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
17 package org.apache.taglibs.standard.examples.taglib;
18
19 import javax.servlet.jsp.JspException JavaDoc;
20 import javax.servlet.jsp.JspTagException JavaDoc;
21 import javax.servlet.jsp.jstl.core.LoopTag;
22 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
23
24 /**
25  * <p>Tag handler for &lt;odd&gt;
26  *
27  * @author Pierre Delisle
28  * @version $Revision: 1.3 $ $Date: 2004/02/28 01:01:41 $
29  */

30 public class OddTag extends TagSupport JavaDoc {
31     
32     //*********************************************************************
33
// TagSupport methods
34

35     public int doStartTag() throws JspException JavaDoc {
36         LoopTag iteratorTag = (LoopTag)findAncestorWithClass(
37                 this, LoopTag.class);
38         if (iteratorTag == null) {
39             throw new JspTagException JavaDoc("<odd> must be nested within a LoopTag");
40         }
41         
42         int count = iteratorTag.getLoopStatus().getCount();
43         System.out.println("count: " + count);
44                 System.out.println("count odd/even: " + (count % 2));
45         return (count % 2 == 1) ? EVAL_BODY_INCLUDE : SKIP_BODY;
46     }
47 }
48
49
50
Popular Tags