<html:optionsCollection />标签与LabelValueBean使用方法。
1,在jsp页面上引用:
<html:select property=”bankno” styleId=”bankno” styleClass=”nputstyle2″ onchange=”doChgBankNo(this);” alt=”search”> <html:optionsCollection name=”bnDictionary” property=”bankNoList”/> < /html:select>
这段引用的(<html:optionsCollection name=”bnDictionary” property=”bankNoList”/>)name=bnDictionary是通过userBean进行定义的
<jsp:useBean id=”bnDictionary” scope=”application”></jsp:useBean>
2,后台java代码
bankNoList 为DictionaryBean 这个类下面的属性,返回的结果为list,list里面的值为LabelValueBean
public List getBankNoList(){ Map childMap = getChildDicMap(parentKey); List values; if (childMap == null){ values = new ArrayList(); }else { values = new ArrayList(childMap.size()-1); } List set = Utils.getOrderedList(childMap, new Dictionary.DictionaryComporator()); values.add(new LabelValueBean(DictionaryConstants.PLEASE_SELECT, “”)); for (Iterator it = set.iterator(); it.hasNext();) { Dictionary dictionary = (Dictionary)it.next(); String value = dictionary.getKeyValue(); if (“#”.equals(value)) continue; String label = dictionary.getKeyCaption(); values.add(new LabelValueBean(label, value)); } return values; }
3,在js中获取这个html:optionsCollection 里面的值
function doChgBankNo(obj) {
var selectText = obj.options[obj.selectedIndex].text;//获取lable var selectValue = obj.options[obj.selectedIndex].value;//获取value
}