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

📄 dictselecttag.java

📁 这是一个轻便的j2ee的web应用框架,是一个在多个项目中运用的实际框架,采用struts,hebinate,xml等技术,有丰富的tag,role,navigation,session,dictio
💻 JAVA
字号:
/*
 * Created on 2004-3-25
 *
 */
package com.esimple.service.dict.taglib;

import java.util.*;
import com.esimple.service.dict.*;
import com.esimple.framework.web.taglib.html.*;
import com.esimple.framework.web.init.ESimplePlugIn;
import org.springframework.beans.factory.*;
import javax.servlet.jsp.JspException;
import org.apache.struts.util.ResponseUtils;
import org.apache.struts.util.RequestUtils;
/**
 * @author steven
 *
 */
public class DictSelectTag extends SelectTag {
	private BeanFactory factory;
	private DictManager dicM;
	private void init(){
		factory =(BeanFactory) pageContext.getServletContext()
				.getAttribute(ESimplePlugIn.BEAN_FACTORY);
		dicM = (DictManager)factory.getBean(DictManager.BEAN_CONFIG_NAME);
	}
	private String dictType;
	private String nullLabel;
	private String defaultSelected;
	private String valueBean;
	private String property;
	private String scope;

	public void  setScope(String scope){
		this.scope = scope;
	}
	public String getScope(){
		return this.scope;
	}
		
	public void  setProperty(String property){
		this.property = property;
	}
	public String getProperty(){
		return this.property;
	}
		
	public void  setValueBean(String valueBean){
		this.valueBean = valueBean;
	}
	public String getValueBean(){
		return this.valueBean;
	}
	public void  setDictType(String dictType){
		this.dictType = dictType;
	}
	public String getDictType(){
		return this.dictType;
	}
	
	public void  setNullLabel(String nullLabel){
		this.nullLabel = nullLabel;
	}
	public String getNullLabel(){
		return this.nullLabel;
	}	
	public void  setDefaultSelected(String defaultSelected){
		this.defaultSelected = defaultSelected;
	}
	public String getDefaultSelected(){
		return this.defaultSelected;
	}	
	public int doStartTag() throws JspException {
		if(dictType==null){
			return SKIP_BODY;
		}
		if(dicM ==null ) init();
		ResponseUtils.write(pageContext, renderSelectStartElement());
		return (EVAL_BODY_TAG);
	 }

	 /**
	  * Create an appropriate select start element based on our parameters.
	  * @throws JspException
	  * @since Struts 1.1
	  */
	 protected String renderSelectStartElement() throws JspException {
		if( valueBean != null & property != null) {
			if(RequestUtils.lookup(pageContext, valueBean, scope) != null){
				Object pvalue =RequestUtils.lookup(pageContext, valueBean, property, scope);
				if( pvalue != null ) defaultSelected = pvalue.toString();
			}
				
		}
		if( dicM != null ){
			if( dicM.getDictContent(dictType)== null) return "";
		}
		
		 StringBuffer results = new StringBuffer("<select");
        
		 results.append(" name=\"");

		 results.append(name);
		 results.append("\"");
		 if (accesskey != null) {
			 results.append(" accesskey=\"");
			 results.append(accesskey);
			 results.append("\"");
		 }
		 if (multiple != null) {
			 results.append(" multiple=\"multiple\"");
		 }
		 if (size != null) {
			 results.append(" size=\"");
			 results.append(size);
			 results.append("\"");
		 }
		 if (tabindex != null) {
			 results.append(" tabindex=\"");
			 results.append(tabindex);
			 results.append("\"");
		 }
		 results.append(prepareEventHandlers());
		 results.append(prepareStyles());
		 results.append(">\n");
		 
		 if( nullLabel!= null ){
		 	results.append("<option value=\"\">"+nullLabel +"</option>\n");
		 }
		 if( dicM != null ){
			HashMap contents = dicM.getDictContent(dictType);
			
			Iterator iter = contents.keySet().iterator();
			while( iter.hasNext()){
				String key = iter.next().toString();
				String value = contents.get(key).toString();
				results.append("   <option value=\"");
				results.append(key);
				results.append("\"");
				if( defaultSelected != null && 
					defaultSelected.equalsIgnoreCase(key) ){
					results.append(" selected");	
				}
				results.append(">");
				results.append(value);
				results.append("</option>\n");
			}
		 }
		 return results.toString();
	 }

	public int doEndTag() throws JspException {
		StringBuffer results = new StringBuffer();
		if (saveBody != null) {
			results.append(saveBody);
		}
		results.append("</select>");

		ResponseUtils.write(pageContext, results.toString());

		return (EVAL_PAGE);
	}
}

⌨️ 快捷键说明

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