ITeye博客

struts1 select标签

salute · 2010-10-26 09:35 · 企业架构 · Markdown



后台代码:

model层

   1. public List getMaterielttypeList() throws Exception{
   2.          List objList = new ArrayList();
   3.          MaterieltypeHome mtype = this.getMaterielTypeHome();
   4.          mtype.resetConditions();
   5.          mtype.setOrderbyclause("order by typename");
   6.          Collection mtypelist = mtype.findAll();
   7.          Iterator it = mtypelist.iterator();
   8.         while(it.hasNext()){
   9.             Materieltype obj = (Materieltype) it.next();
  10.            //固定写法,LabelValueBean()第一个参数为displayname,第二个参数为后台使用的值,一般为id。
  11.                     objList.add(new LabelValueBean(obj.getTypename(),String.valueOf(obj.getId())));
  12.          }
  13.         return objList;
  14.      }

Action代码

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

表现层:

   1.


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









评论(0)

暂无评论。

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