📄 listitemtag.java
字号:
/*
*********************************************************************
* 文件 : $Workfile: ListItemTag.java $
* 项目 : 腾龙1.2
* 公司 : 沈阳东软软件股份有限公司
* 日期 : $Date: 03-12-10 18:21 $
* 说明 :
**********************************************************************
* 版本历史:
* $Log: /4 开发工作目录/src/com/neusoft/taglibs/list/ListItemTag.java $
*
* 1 03-12-10 18:21 Lihg
*
* 1 03-12-10 8:44 Lihg
*
* 1 03-05-20 9:46 Lihg
*********************************************************************
*/
package com.neusoft.taglibs.list;
import java.io.*;
import java.lang.reflect.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import com.neusoft.util.CommonUtil;
/**
* 这个tag会根据相应的数据对象List,列出单个数据对象,与ListTag配套使用
*
*@author <a href="mailto:lihg@neusoft.com">李红国</a>
*@created 2003年5月19日
*/
public class ListItemTag
extends TagSupport {
private Object item = null;
private String property = null;
private String precisionString = null;
/**
* 构造对象 ListItemTag
*/
public ListItemTag() {
super();
}
/**
* 设定ListItemTag object-property的属性值
*
*@param property 属性 property 的值
*/
public void setProperty(String property) {
this.property = property;
}
/**
* 遇到tag时触发
*
*@return 操作标志
*@exception JspTagException 异常描述
*/
public int doStartTag() throws JspTagException {
// check if items tag is in list tag
ListTag listTag = (ListTag) findAncestorWithClass(this, ListTag.class);
if (listTag == null) {
throw new JspTagException(
"ListDataTag: ListItem tag not inside items tag");
}
item = listTag.getCurrentItem();
if (listTag == null) {
throw new JspTagException("ListDataTag: There is no item to list.");
}
return SKIP_BODY;
}
/**
* tag结束时触发
*
*@return 描述返回值信息
*@exception JspTagException 异常描述
*/
public int doEndTag() throws JspTagException {
// print out attribute
try {
JspWriter out = pageContext.getOut();
String targetText = getText();
//if (format != null) targetText = formatText(targetText);
pageContext.getRequest().setAttribute(property, targetText);
out.print(targetText);
}
catch (IOException ioe) {
System.err.println("ListDataTag: Error printing attribute: " + ioe);
throw new JspTagException("ListDataTag: IO Error printing attribute.");
}
return (EVAL_PAGE);
}
/**
* Using the current Object use reflection to obtain the String data from
* the element method the same as a JavaBean would use: <br>
* <br>
* e.g. a getXXXX method which has no parameters <br>
* The target method is the property attribute The default method that is
* called is the toString method on the object.
*
*@return 属性 text的值
*@exception JspTagException 异常描述
*/
private String getText() throws JspTagException {
String targetMethod = "getValue";
Object returnValue = null;
try {
// no arguments are needed
Class[] args = {
String.class};
Object[] params = {
property};
Method m = item.getClass().getMethod(targetMethod, args);
if (m == null) {
throw new JspTagException(
"ListDataTag: There is no method by the name of " + targetMethod);
}
returnValue = m.invoke(item, params);
}
catch (java.lang.NoSuchMethodException ex) {
throw new JspTagException("ListDataTag: Method for property " + property +
" not found.");
}
catch (java.lang.reflect.InvocationTargetException ex) {
throw new JspTagException("ListDataTag: Error calling method " +
targetMethod + ":" + ex);
}
catch (java.lang.IllegalAccessException ex) {
throw new JspTagException("ListDataTag: Error calling method " +
targetMethod + ":" + ex);
}
// do casting of Integers and Dobules here
if (returnValue instanceof java.lang.String) {
returnValue = (String) returnValue;
}
else if (returnValue instanceof java.lang.Integer) {
returnValue = ( (Integer) returnValue).toString();
}
else if (returnValue instanceof java.lang.Double) {
returnValue = ( (Double) returnValue).toString();
}
else if (returnValue instanceof java.lang.Float) {
returnValue = ( (Float) returnValue).toString();
}
else if (returnValue instanceof java.math.BigDecimal) {
returnValue = ( (java.math.BigDecimal) returnValue).toString();
}
else if (returnValue == null) {
returnValue = "";
}
else {
throw new JspTagException("ListDataTag: Error extracting property: Can not handle the return type for property " +
property);
}
return CommonUtil.parseHtml( (String) returnValue);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -