注意事项:
(1):In HTML the tag has no end tag.HTML中标签不需要关闭。In XHTML the tag must be properly closed. 在XHTML中标签必须合理关闭。
在使用struts1中包含的下拉列表的标签包含:
生成HTML元素
:生成HTML元素
:生成一组HTML元素
生成一组HTML元素。
其中生成HTML元素,表示下拉列表框或多选列表。在标签中可以包含多个,, 元素。
size属性:指定每次在网页上显示的可选项的数目。
multipe属性:指定是否支持多项选择,如果设置为true,就表示多选列表,支持多项选择。否则只表示下拉列表。只支持单选操作。默认是false。
property属性:与ActionForm Bean中的某个属性对应,这个属性用来存放用户在列表上选中选项的值。在单项选择的情况下,ActionForm Bean中的对应属性对应该列表上选项的值。在单项选择情况下,
ActionForm Bean对应属性应该定义为简单类型(不能为数组),在多项选择情况下,ActionForm Bean中的对应属性应该定义为数组类型,以便存放用户选择的多个选项。
a
使用sturts1标签完成下拉框。基本示例如下:。本地使用国产框架Buffalo.
jsp脚本:
var buffaloEmpInfo = new Buffalo('' + '/xmlhttp');
var END_POINT="/xmlhttp";
function result(reply){
var returnResult = reply.getResult();
$("#options").empty();
if(returnResult.length > 0){
for(var index = 0 ; index < returnResult.length ; index++){
$("#options").append("●");
}
}else{
$("#nobutton").attr("disabled", true);
}
}
使用coolection属性指定存在某个范围中的集合来生成列表项,注意coolection属性指定的集合,该对象的每一个元素为一个Bean。
例如有如下实体类
package com.pojo;
public class Users {
private String userName;
private String userValue;
public Users(){}
public Users(String userName,String userValue){
this.userName=userName;
this.userValue=userValue;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserValue() {
return userValue;
}
public void setUserValue(String userValue) {
this.userValue = userValue;
}
}
将实体类实例放入ArrayList列表然后放入reqeust范围内
Users u1=new Users("1","高中");
Users u2=new Users("2","本科");
Users u3=new Users("3","硕士");
Users u4=new Users("4","博士");
ArrayList array=new ArrayList();
array.add(u1);
array.add(u2);
array.add(u3);
array.add(u4);
request.setAttribute("xueli",array);
使用标签生成可选项
collection="xueli"
property="userName"
labelProperty="userValue"/>
:
collection指定存放在request范围内的集合
property指定实际值
labelProperty指定显示到页面上的文本。
当使用property属性和labelProperty属性时,会根据属性指定的名称调用相应Bean中的getXXX方法来获得属性值。
生成HTML效果如下
高中
本科
硕士
博士
其中collection为一个集合,一般是个ArrayList,displayName为前台显示的名称,value为后台实际使用的值.
例: