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

📄 tabletag.java

📁 一个java工作流引擎
💻 JAVA
字号:
package org.jbpm.web.tag;

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

import org.apache.commons.logging.*;
import org.apache.struts.taglib.tiles.util.*;

public class TableTag extends TagSupport {

  private String id = null;
  private String name = null;
  private String property = null;
  private List columns = new ArrayList();

  public void release() {
    id = null;
    name = null;
    property = null;
    columns = new ArrayList();
  }
    
  private void startTable(JspWriter jspOut) throws IOException {
    jspOut.println( "" );
    jspOut.println( "" );
    jspOut.println( "<!-- START OF TABLE -->" );
    jspOut.println( "<table cellspacing=1>" );
  }
  private void endTable(JspWriter jspOut) throws IOException {
    jspOut.println( "</table>" );
    jspOut.println( "<!-- END OF TABLE -->" );
    jspOut.println( "" );
  }

  private void startHeaderRow(JspWriter jspOut) throws IOException {
    startRow( jspOut );
  }
  private void endHeaderRow(JspWriter jspOut) throws IOException {
    endRow( jspOut );
  }

  private void startRow(JspWriter jspOut) throws IOException {
    jspOut.println( "  <tr>" );
  }
  private void endRow(JspWriter jspOut) throws IOException {
    jspOut.println( "  </tr>" );
  }

  private void startHeaderCell(JspWriter jspOut) throws IOException {
    jspOut.print( "    <th>" );
  }
  private void endHeaderCell(JspWriter jspOut) throws IOException {
    jspOut.println( "</th>" );
  }

  private void startCell(JspWriter jspOut) throws IOException {
    jspOut.print( "    <td>" );
  }
  private void endCell(JspWriter jspOut) throws IOException {
    jspOut.println( "</td>" );
  }

  public int doStartTag() throws JspException {
    
    log.debug( "starting table tag with ..." );
    log.debug( "  name: " + name );
    log.debug( "  property: " + property );
    log.debug( "  columns: " + columns );
    
    return EVAL_BODY_INCLUDE;
  }
    
  public int doEndTag() throws JspException {
    JspWriter jspOut = pageContext.getOut();
    
    log.debug( "ending table tag with ..." );
    log.debug( "  name: " + name );
    log.debug( "  property: " + property );
    log.debug( "  columns: " + columns );
    
    try {
      startTable( jspOut );

      startHeaderRow( jspOut );
      Iterator columnIter = columns.iterator();
      while (columnIter.hasNext()) {
        Column column = (Column) columnIter.next();

        startHeaderCell( jspOut );
        column.writeTitle( pageContext );
        endHeaderCell( jspOut );
      }
      endHeaderRow( jspOut );
      
      Iterator rowIter = getCollection().iterator();
      while (rowIter.hasNext()) {
        startRow( jspOut );
        Object rowObject = rowIter.next();
        columnIter = columns.iterator();
        while (columnIter.hasNext()) {
          Column column = (Column) columnIter.next();
          
          startCell( jspOut );
          column.writeCell( rowObject, pageContext );
          endCell( jspOut );
        }
        endRow( jspOut );
      }

      endTable( jspOut );
    
    } catch (IOException e) {
      e.printStackTrace();
      throw new JspException( "table couldn't be displayed : " + e.getMessage() );
    }
    
    release();
    
		return EVAL_PAGE;
	}

	private Collection getCollection() throws JspException {
    Collection collection = null;
    try {
			Object bean = TagUtils.findAttribute( name, pageContext );
			if ( bean != null ) {
			  collection = (Collection) TagUtils.getProperty( bean, property );
			}
		} catch (Exception e) {
			e.printStackTrace();
      throw new JspException("couldn't find the collection for the table tag : " + e.getMessage() );
		}
    return collection;
	}

  public void setId(String id) { this.id = id; }
  public void setName(String name) { this.name = name; }
  public void setProperty(String property) { this.property = property; }

  public void add(Column column) {
    columns.add( column );
  }
  
  private static Log log = LogFactory.getLog(TableTag.class);
}

⌨️ 快捷键说明

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