<html:optionsCollection />标签与LabelValueBean使用方法
2013-12-28 19:35
1296 查看
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" class="com.myself.fund.bean.DictionaryBean" 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
}
<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" class="com.myself.fund.bean.DictionaryBean" 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
}
相关文章推荐
- <html:select>,<html:option>,<html:options>,<html:optionsCollection>标签使用
- <html:select>,<html:option>,<html:optionsCollection>标签使用
- HTML中让图片滚动的<marquee>标签的使用方法
- <html:select>,<html:option>,<html:options>,<html:optionsCollection>标签使用
- 实现下拉内容从数据库中动态读取--->Struts标签:和LabelValueBean的使用
- 使用html <a href=""/>标签连接action的方法
- <html:select>,<html:option>,<html:options>,<html:optionsCollection>标签使用
- <bean:write/>标签使用方法详解
- struts2 用标签 <s:property value='[]'/> 取值 json 含有转义字符的解决方法
- html工作中表格<tbody>标签的使用技巧
- Java中使用XML标签<x:transform />转化XML为HTML
- Spring配置文件中使用ref local与ref bean的区别. 在ApplicationResources.properties文件中,使用<ref bean>与<ref local>方法如下
- 黑马程序员-<select>标签以及<label>标签的使用
- JSP标签的<jsp:useBean>和<jsp:setProperty><jsp:getProperty>的使用
- HTML表格标签的使用-<table>
- struts中<html:radio>标签默认选中的解决方法《转载》
- html的锚标签<a>中使用javascript代码
- Android UI设计之<六>使用HTML标签,实现在TextView中对部分文字进行加粗显示
- 关于使用Html <audio>标签播放视频文件的问题
- Mybatis <collection> 标签使用。