0-15
15-20
20-30
30 or above
第二种:把选项放在一个Collection中(这里使用List).在实际项目中,更多的是可能数据来源于db,文件等。这种情况用得比较多。
把option放在list中的过程在Action中作处理
//prepare the age selector list.
List ageList =new ArrayList();
ageList.add(new LabelValueBean("0-15","0-15"));
ageList.add(new LabelValueBean("15-20","15-20"));
ageList.add(new LabelValueBean("20-30","20-30"));
ageList.add(new LabelValueBean("30 or above","30 or above"));
request.setAttribute("AList",AList);
这里使用了LabelValueBean,可以不用的,象
只要在AList中填入的bean有value和id属性就可以
第三种,把此list 作为Form 的一个属性.
在Form 中添加AList 的setter和getter. Form中作如下处理。
//the list can be a form property.
f.setAgeList(AList);
1. 从数据库中获得数据,你应该在Action里面取得数据后,将数据放到Request里面
2. 数据取出来后放在一个List或Collection或Map里面,我习惯用List
3. 从List或其它的容器中取数据应该用 或
4. 和外层必须用,所以这个属性你必须在FormBean里定义
5. 由于你要用到这些标签,所以你必须定义FormBean
6.
从Action取数据,以List为例
List list = xxxxx;//从数据库中取得下拉列表中的数据
request.setAttribute("list",list);
在页面显示
...
...
补充一点点:
因为数据你要从 数据库去取, 所以一般在 action 里调用 DAO ,作为 request 的一个属性传到页面上; 这时一般用 标签
另外,如果数据不从数据库去取,而是代码固定的,则一般把这种放到 ActionForm 里,作为属性在页面上取,这时一般用
posted on 2006-07-10 13:52 船长 阅读(337) 评论(0) 编辑 收藏 所属分类: J2EE