4 doubleselect
doubleselect标签生成上下两个select控件,上面的控件选择的option会导致下面select控件的options发生变化。
Attributes | Description |
name | 对应action中的变量名称,生成的parent select的name属性 |
doubleName | Required,对应action中变量的名称,生成的child select的name属性 |
list | Required,生成的parent select元素显示的可选列表,参照combobox的list属性 |
doubleList | Required,生成的child select元素显示的可选列表,相当于child select标签的list属性 |
listKey | 生成的parent select 的option元素的value属性 |
listValue | 生成的parent select的option元素的显示内容 |
doubleListKey | Child select的选项的value属性 |
doubleListValue | Child select的option元素显示的内容 |
headerKey | 设置parent select的第一个选项的值 |
headerValue | 设置parent select第一个选项的显示内容 |
Jsp code:
<s:doubleselect name="hobbyName" list="#session.hobbyList" listKey="hobbyId" listValue="hobbyName" headerKey="-1" headerValue="Please Select" doubleName="hobbyClass" doubleList="top.courses" />
Page source code:
<select name="hobbyName" id="testTags_hobbyName" οnchange="testTags_hobbyNameRedirect(this.options.selectedIndex)">
<option value="1">Football</option>
<option value="2">Basketball</option>
</select>
<br />
<select name="hobbyClass" id="testTags_hobbyClass">
</select>
<script type="text/javascript">
......
......
function testTags_hobbyNameRedirect(x) {
//这里是由标签生成的js代码,来触发child select的选项更新
}
</script>
Prepare action:
Parent select显示的内容一般是从db中取得,假设Hobby类里有个属性为courses,类型为List<String>,生成的child select就绑定到这个list上,下面是准备数据:
List<String> courses_1 = new ArrayList<String>();
courses_1.add("Sunday Class");
courses_1.add("Monday Class");
courses_1.add("Saturday Class");
List<String> courses_2 = new ArrayList<String>();
courses_2.add("Wednesday Class");
courses_2.add("Friday Class");
courses_2.add("Monday Class");
courses_2.add("Saturday Class");
courses_2.add("Sunday Class");
hobby_1.setCourses(courses_1);
hobby_2.setCourses(courses_2);
hobbyList.add(hobby_1);
hobbyList.add(hobby_2); //this list load from database
map.put("hobbyList", hobbyList);
return SUCCESS; //return xxx.jsp
Action class:
private String hobbyName; //with getter/setter method
Private String hobbyClass; //with getter/setter method
Result:
在页面提交到Action后,hobbyName的值为parent select选中的选项值,hobbyClass的值为child select 选中的选项值。