1 13 package com.tonbeller.wcf.sqltable; 14 15 import java.io.IOException ; 16 17 import javax.servlet.jsp.JspException ; 18 import javax.servlet.jsp.jstl.core.LoopTag; 19 import javax.servlet.jsp.jstl.core.LoopTagStatus; 20 import javax.servlet.jsp.tagext.TagSupport ; 21 22 import org.apache.log4j.Logger; 23 24 29 public class EvenOddTag extends TagSupport { 30 String clazz; 31 String even; 32 String odd; 33 34 private static final Logger logger = Logger.getLogger(EvenOddTag.class); 35 36 public int doStartTag() throws JspException { 37 LoopTag tag = (LoopTag) super.findAncestorWithClass(this, LoopTag.class); 38 if (tag == null) 39 throw new JspException ("must be nested in a loop tag"); 40 41 LoopTagStatus status = tag.getLoopStatus(); 42 String s; 43 if (status.getCount() % 2 == 0) 44 s = (clazz == null) ? even : clazz + "-even"; 45 else 46 s = (clazz == null) ? odd : clazz + "-odd"; 47 try { 48 pageContext.getOut().print(s); 49 } catch (IOException e) { 50 logger.error(null, e); 51 } 52 53 return super.doStartTag(); 54 } 55 56 public void setClazz(String clazz) { 57 this.clazz = clazz; 58 } 59 60 public void setEven(String even) { 61 this.even = even; 62 } 63 public void setOdd(String odd) { 64 this.odd = odd; 65 } 66 } 67 | Popular Tags |