1 16 package org.apache.taglibs.utility.lang; 17 18 import java.io.IOException ; 19 import javax.servlet.jsp.*; 20 import javax.servlet.jsp.tagext.*; 21 22 29 30 public class ForTag extends BodyTagSupport { 31 32 private int iterations; 33 private String varName = "_count"; 34 private int count = 0; 35 36 public String getVarName() { 37 return this.varName; 38 } 39 40 public void setVarName(String val) { 41 this.varName = val; 42 } 43 44 public void setBegin(int begin) { 45 this.count = begin; 46 } 47 48 public int getIterations() { 49 return iterations; 50 } 51 52 public void setIterations(int val) { 53 this.iterations = val; 54 } 55 56 public int doStartTag() { 57 count = 0; 58 return EVAL_BODY_TAG; 59 } 60 61 public void doInitBody() throws JspException { 62 pageContext.setAttribute(getVarName(),new Integer (count)); 63 } 64 65 public int doAfterBody() throws JspException { 66 try { 67 count++; 68 if (count < getIterations()) { 69 pageContext.setAttribute(getVarName(),new Integer (count)); 70 return EVAL_BODY_TAG; 71 } 72 bodyContent.writeOut(bodyContent.getEnclosingWriter()); 73 return SKIP_BODY; 74 } catch (IOException ex) { 75 throw new JspException(ex.getMessage()); 76 } 77 } 78 79 } 80 | Popular Tags |