⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iteratetag.java

📁 java版源代码,里面包含很多源代码,大家可以看看.
💻 JAVA
字号:
package com.trulytech.mantis.tag;

import java.io.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import com.trulytech.mantis.result.DBResult;
import java.util.Iterator;
import java.util.ArrayList;

/**
 *
 * <p>Title: Mantis</p>
 *
 * <p>Description: 获得DBRuslt的值</p>
 *
 * <p>Copyright: Copyright (c) 2002</p>
 *
 * <p>Company: </p>
 *
 * @author Wang Xian
 * @version 1.1
 */

/*例如********************************************************
 <bean:foreach name="Result">
   <tr>
   <td width="100%"><bean:value col="0" /></td>
   </tr>
 </bean:foreach>

 */
public class IterateTag
    extends BodyTagSupport {

  //叠代器
  private ArrayList it = null;
  private int i = 0;
  /**
   * 覆盖doStartTag方法
   * @return int
   * @throws JspTagException
   */
  public int doStartTag() throws JspTagException {

    return continueNext(it);
  }

  /**
   * 结束body
   * @return int
   * @throws JspTagException
   */
  public int doAfterBody() throws JspTagException {

    return continueNext(it);
  }

  /**
   * 结束标志
   * @return int
   * @throws JspTagException
   */
  public int doEndTag() throws JspTagException {
    try {
      if (pageContext.findAttribute("array") == null)
        return SKIP_BODY;
      else {
        pageContext.removeAttribute("array");

        if (bodyContent != null)
          bodyContent.writeOut(bodyContent.getEnclosingWriter());
      }
    }
    catch (IOException e) {
      throw new JspTagException("Fatal error");
    }

    return SKIP_BODY;
  }

  /**
   * 设置DBResult的值
   * @param Name String
   */
  public void setName(String Name) {
    if (this.pageContext.findAttribute(Name) != null) {
      if (this.pageContext.findAttribute(Name) instanceof DBResult) {
        it = ( (DBResult)this.pageContext.findAttribute(Name)).ResultBuffer;

      }
      else
        it = null;
    }
    else
      it = null;
  }

  /**
   * 将下一个结果放在PageContext中的array对象中
   * @param it Iterator
   * @return int
   * @throws JspTagException
   */
  protected int continueNext(ArrayList it) throws JspTagException {
    if (it == null) {

      return SKIP_BODY;
    }
    else if (it.size() > i) {
      pageContext.setAttribute("array", it.get(i));
      i++;
      return EVAL_BODY_AGAIN;
    }
    else {
      i = 0;
      return SKIP_BODY;
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -