itemattributetag.java

来自「一个免费wap站」· Java 代码 · 共 72 行

JAVA
72
字号
/*
 * ItemAttributeTag
 * ----------------
 * This abstract class works with the list tag package and prints out an
 * attribute of a particular type of item.  The item is retrieved from the
 * outer items tag (an exception is thrown if not inside one).  Depending on
 * the value of the "attribute" attribute a different string is printed - this
 * should be determined in the implementation of createText(), which allows
 * for the details of the class of the item.
 */

package com.eline.wap.common.taglib;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import com.eline.wap.common.util.AppLogger;
/**
 * 
 * @author Lucifer
 *
 */
public abstract class ItemAttributeTag extends TagSupport {

	private static final long serialVersionUID = -965028925620230330L;

	protected Object item = null;
	protected String name = null;

	/**
	 * 
	 * @throws JspException
	 */
	public int doStartTag() throws JspException {
		// check if itemAttribute tag is in items tag
		ItemsTag itemsTag = (ItemsTag) findAncestorWithClass(this, ItemsTag.class);
		if (itemsTag == null) {
			throw new JspTagException("ItemAttributeTag: itemsAttribute tag not inside items tag");
		}
		item = itemsTag.getCurrentItem();

	    // print out attribute
	    try {
	    	JspWriter out = pageContext.getOut();
	    	out.print(createText());
	    } catch(IOException e) {
	        AppLogger.error("ItemAttributeTag: Error printing attribute: " + e);
	    }

	    // there should be no body to process
	    return SKIP_BODY;
	}

	/**
	 * setter for tag attribute
	 * @param attribute
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * 
	 * protected abstract methods
	 */
	protected abstract String createText();
}

⌨️ 快捷键说明

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