前言:我在论坛上看到很多多Struts的taglib批评的帖子,估计是大家对taglib的使用还是不熟悉的原因吧
现在特别对taglib中select选择筐的实现作个解释 目的是让大家知道taglib是无比的好用
首先在 listSearchForm中定义一个ArrayList ,Set等集合接口
private ArrayList departmentList;
并添加set,get方法,在Form里定义好了 然后就是准备数据,只要从Delegate把数据赛进Form里
数据准备,顶好的是把数据弄成LableValueBean形式,Struts里有这个Bean的定义,你也可以自己创建
一个类似的LableValueBean
//定义一个_deptList而且他的Type为Collection 属性为Form里定义的departmentList,name则是
跟Struts-config.xml配置文件里的Form名字一样 使用效果如下:
<bean:define id="_deptList" name="listSearchForm" property="departmentList" type="java.util.Collection" scope="request" />
<html:select property="deptId" size="1">
<html:options collection="_deptList" property="value" labelProperty="label" />
</html:select>