Struts中的下拉列表标签的使用
来源:互联网 发布:ipad数据恢复 编辑:程序博客网 时间:2024/05/22 04:55
页面中经常用到下拉列表,下面是个人对于STRUTS中标签使用的一点总结:
STRUTS中的下拉选择列表标签必须嵌套在<html:form>标签中,包括:
1.<html:select>
2.<html:option>
3.<html:options>
4.<html:optionsCollection>
使用时嵌套如下:
<html:select property="ationForm.property">
<html:option>或<html:options>或<html:optionsCollection>
</html:select>
其中property为ActionForm中对应的一个属性.
1.<html:option>
<html:option value="value">displayName</html:option>
其中value为实际使用的值(赋值到ActionForm对应的属性中) displayName页面中显示的信息.
例:<html:option value=""></html:option>显示一个空白选择,值为"".
2..<html:options>
<html:options collection="collection" labelProperty="displayName" property="value"/>
其中collection为一个集合,一般是个ArrayList,displayName为前台显示的名称,value为后台实际使用的值.
例:<html:options collection="arrayList" labelProperty="name" property="id" />
3..<html:optionsCollection>
<html:optionsCollection property="actionForm.property" label="displayName" value="value"/>
其中property为ActionForm中的一个属性,为一个集合.displayName为前台显示的名称,value为后台实际使用的值.
例:<html:optionsCollection property="listProperty" label="name" value="id" />
补充一点:如果要从 数据库去取数据,一般是在 action 里调用 DAO ,把结果存入一个ArrayList作为 request 的一个属性传到页面上; 这时一般用 <html:options .../> 标签.另外,如果数据不从数据库去取,而是代码固定的,则一般把这种放到 ActionForm 里,作为属性在页面上取,这时一般用 <html:optionsCollection ... />
实例代码:
<html:form action="/welcome" method="post">
<html:select property="colorid">
<html:options collection="beans" property="label" labelProperty="value"/>
</html:select>
</html:form>
//form bean代码
public class WelcomeForm extends ActionForm ...{
private String colorid; //用于保存用户选择的值
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) ...{
// TODO Auto-generated method stub
return null;
}
/** *//**
* Method reset
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) ...{
// TODO Auto-generated method stub 初始化值
List list=new ArrayList();
list.add(new LabelValueBean("pink","this is pink"));
list.add(new LabelValueBean("red","this is red"));
request.setAttribute("beans", list);
}
public String getColorid() ...{
return colorid;
}
public void setColorid(String colorid) ...{
this.colorid = colorid;
}
}
- Struts中的下拉列表标签的使用
- Struts中的下拉列表标签的使用
- struts标签 select 下拉列表赋初值问题
- volist标签的下拉列表
- s标签s:select下拉列表的使用
- s标签s:select下拉列表的使用
- struts 中 使用下拉列表框
- Struts中巧用java枚举类生成select标签的下拉列表
- Struts中巧用java枚举类生成select标签的下拉列表
- 关于list集合传到jsp,在struts的select标签中显示下拉列表问题
- 表单中的下拉列表 使用
- 下拉列表的使用
- struts标签的使用
- struts标签的使用
- struts 标签的使用
- 下拉列表struts
- STRUTS下拉列表
- 使用标签创建下拉列表和多选列表框
- 我的电脑不显示u盘解决方法
- IT企业根本就不知道资深的含义
- 《数据挖掘——概念和技术》笔记之概论
- 遭遇冷漠
- 《数据挖掘——概念和技术》笔记之数据预处理
- Struts中的下拉列表标签的使用
- effective Java 学习笔记(三)
- 测试
- 如何安全使用U盘等移动存储设备
- C#实现数据库备份(以Sql Server为例)
- javascript调用xml为网页添加广告
- Oracle导入程序Imp的使用详解
- 走上正轨
- 电力知识-1