Java 后台控制 前台Select标签显示值 功能

package com.mzb.cozy.util;

import java.util.List;

public class JspSelectUtil {
	public static String generateSelectOption(List datas, String defaultValue){
		StringBuffer optionStrBuffer = new StringBuffer();
		OptionUtil optionUtil = new OptionUtil();
		
		if(datas==null)
			return "";
		
		//循环列表
		for (int i = 0; i < datas.size(); i++) {
			optionUtil = (OptionUtil)datas.get(i);
			String selected = "";
			
			String key = optionUtil.getKey();
			
			String displayValue = optionUtil.getDisplayValue();
			String value = optionUtil.getValue();
			if (defaultValue!=null) {
				if (null != key && key.equals(defaultValue)) {
					selected = "selected";
				}else if(null!= value && value.equals(defaultValue)) {
					selected = "selected";
				}
			}
			
			if(displayValue!=null&&displayValue!=""){
				//拼接选项html
				optionStrBuffer.append("<option value=\"").append(key).append(
						"\" ").append("title=\"").append(displayValue).append("\" ").append(selected).append(">");
			}else{
				//拼接选项html
				optionStrBuffer.append("<option value=\"").append(key).append(
						"\" ").append(selected).append(">");
			}
			optionStrBuffer.append(value).append("</option>");
		}
		
		return optionStrBuffer.toString();
	}
}

   前台JSP页面

<select name="Bean.beanId"	class="common_select" id="prjpricebaseid">
<option value=""></option>			
<%=JspSelectUtil.generateSelectOption(BeanInfoList, bean.beanId)%>
</select>

 

你可能感兴趣的:(select)