1 16 17 package org.apache.taglibs.standard.examples.taglib; 18 19 import javax.servlet.jsp.JspException ; 20 import javax.servlet.jsp.JspTagException ; 21 import javax.servlet.jsp.jstl.core.LoopTag; 22 import javax.servlet.jsp.tagext.TagSupport ; 23 24 30 public class OddTag extends TagSupport { 31 32 35 public int doStartTag() throws JspException { 36 LoopTag iteratorTag = (LoopTag)findAncestorWithClass( 37 this, LoopTag.class); 38 if (iteratorTag == null) { 39 throw new JspTagException ("<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 |