ITeye博客

struts1.x 后台读取数据至html:select标签方法

zwfc · 2008-11-18 12:10 · Markdown

后台代码:

model层

  1. publicListgetMaterielttypeList()throwsException{
  2. ListobjList=newArrayList();
  3. MaterieltypeHomemtype=this.getMaterielTypeHome();
  4. mtype.resetConditions();
  5. mtype.setOrderbyclause("orderbytypename");
  6. Collectionmtypelist=mtype.findAll();
  7. Iteratorit=mtypelist.iterator();
  8. while(it.hasNext()){
  9. Materieltypeobj=(Materieltype)it.next();
  10. //固定写法,LabelValueBean()第一个参数为displayname,第二个参数为后台使用的值,一般为id。
  11. objList.add(newLabelValueBean(obj.getTypename(),String.valueOf(obj.getId())));
  12. }
  13. returnobjList;
  14. }

Action代码

  1. //实例化model
  2. LldServicesservices=newLldServices(conn);
  3. //取出list并设置到request属性中。
  4. request.setAttribute("mtypelist",services.getMaterielttypeList());

表现层:

  1. <html:selectproperty="typeid">
  2. <!--mtypelist为request中设置的属性值labelProperty="label"property="value"固定写法-->
  3. <html:optionscollection="mtypelist"labelProperty="label"property="value"/>
  4. </html:select>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。