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

📄 listtag.java

📁 招标投标网上系统
💻 JAVA
字号:
/*
 * $Id: ListTag.java,v 1.4 2001/10/26 22:55:55 ro89390 Exp $
 * Copyright 2000 Sun Microsystems, Inc. All rights reserved.
 * Copyright 2000 Sun Microsystems, Inc. Tous droits r?erv?.
 */

package com.neusoft.taglibs.list;

import java.io.*;
import java.util.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

/**
 *
 * This class allows you to retrieve a parameter from the request and output it to the page
 * This should allow you to avoid expressions for extracting parameter info.
 *
 */

public class ListTag
    extends BodyTagSupport {

  private Iterator iterator;
  private int startIndex = -1;
  private int index;
  private int size;
  private String collectionId;
  private String scope;
  private Object currentItem = null;

  public ListTag() {
    super();
  }

  public void setCollectionId(String collectionId) {
    this.collectionId = collectionId;
  }

  public void setScope(String scope) {
    this.scope = scope.toLowerCase();
  }

  public void setStartIndex(int startIndex) {
    this.startIndex = startIndex;
  }

  public void setSize(int size) {
    this.size = size;
  }

  public int doStartTag() throws JspTagException {
    Object targetObject = null;
    Collection collection = null;
    if (scope.equals("request")) {
      targetObject = pageContext.getRequest().getAttribute(collectionId);
    }
    else if (scope.equals("session")) {
      targetObject = pageContext.getSession().getAttribute(collectionId);
    }
    else if (scope.equals("page")) {
      targetObject = pageContext.getAttribute(collectionId);
    }
    if (targetObject == null) {
      throw new JspTagException("ListTag: Collection " + collectionId +
                                " not found in " + scope + " scope.");
    }
    else if (targetObject instanceof java.util.Collection) {
      collection = (Collection) targetObject;
    }
    else {
      throw new JspTagException("ListTag: Iterator " + collectionId +
                                " is not an instance of java.util.Collection.");
    }
    iterator = collection.iterator();
    if (!iterator.hasNext()) {
      return (SKIP_BODY);
    }
    currentItem = iterator.next();
    //System.out.println(currentItem.);
    return (EVAL_BODY_TAG);
  }

  // process the body again until the specified length with the next item if it exists
  public int doAfterBody() {
    if (iterator.hasNext()) {
      currentItem = iterator.next();
      return (EVAL_BODY_TAG);
    }
    else {
      return (SKIP_BODY);
    }
  }

  /**
   *
   * Meant for use by ListItem tags
   *
   */

  public Object getCurrentItem() {
    return currentItem;
  }

  public int doEndTag() throws JspTagException {
    try {
      BodyContent body = getBodyContent();
      if (body != null) {
        JspWriter out = body.getEnclosingWriter();
        out.print(body.getString());
      }
    }
    catch (IOException ioe) {
      System.err.println("Error handling items tag: " + ioe);
    }
    return EVAL_PAGE;
  }
}

⌨️ 快捷键说明

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