収集JSPカスタムラベルEL式の取得問題


ソース:http://bbs.csdn.net/topics/210040287
コメント:
ラベルの例をあげます。自分で見てください。ラベル:tld.xml
        Voucher CodeToName        comple.itown.cm.fee.voucher manage r.util.Voucher CodeToNameTag        JSP                    コード            true            true        Voucher CodetoNameTag.java
package com.itown.crm.fee.vouchermanager.util;

import java.util.ArrayList;

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

import org.apache.commons.lang.StringUtils;
import org.apache.taglibs.standard.tag.el.core.ExpressionUtil;

import com.itown.crm.fee.vouchermanager.po.FeeVoucherInfo;
import com.itown.crm.util.DaoUtil;
import com.itown.framework.persistence.CachedRowSet;
import com.itown.util.ormapping.BeanHelper;

public class VoucherCodeToNameTag extends TagSupport {
	
	protected String code = "";

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}
	
	public int doStartTag() throws JspException {
		//     
		evaluateExpressions();
		//      NUll   "",      
		if(StringUtils.isBlank(code)) {
			return super.doStartTag();
		}
		try {
			String name = null;
			StringBuffer sql = new StringBuffer();
			sql.append("select * from FEE_VOUCHER_INFO where VOUCHER_ID='");
			sql.append(code);
			sql.append("'");

			CachedRowSet rs = DaoUtil.executeQuery(sql.toString());
			
			ArrayList list = BeanHelper.mapBeansByRS(rs, FeeVoucherInfo.class);
			if(list.size() > 0){
				name = ((FeeVoucherInfo)list.get(0)).getVoucherName();
			}
			this.pageContext.getOut().print(StringUtils.trimToEmpty(name));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SKIP_BODY;
	}
	private void evaluateExpressions() {
		try {
			code = (String) ExpressionUtil.evalNotNull("VoucherCodeToName", "code", code, java.lang.Object.class, this, pageContext); //             
        }
        catch(Exception ex) {
        	code = null;
        }
	}

}