struts2的doubleselect标签的使用

来源:互联网 发布:社交网络 相似电影 编辑:程序博客网 时间:2024/05/16 06:46

效果图:

jsp页面:

期刊类型:<s:doubleselect name="qikan.fathertype" list="categoryList" listKey="oid" listValue="name"  theme="doubleselect" doubleName="qikan.sontype" doubleList="map.get(top.oid)" doubleListKey="oid" doubleListValue="name" cssStyle="width:120">
     </s:doubleselect>
  

其中name定义的某个对象的属性,list的值是action传过来的

 

public class Category implements java.io.Serializable {

 // Fields

 private Integer oid;

 private String name;

 private Integer parentid;

}

 

action里面的代码:

private List<Category> fatherList;//  期刊父类型

 

private List<Category> sonList;// 期刊子类型

 

private Map<Integer, List<Category>> map = new HashMap<Integer, List<Category>>();// 存放子类型

 

public String toAddQk() {

    fatherList= dao.listCategoryBy(0);// 查出所有父类型,parentid为0的为父类型


    for (Category category : categoryList) {
        sonList = dao.listCategoryBy(category.getOid());// 根据父类型的id查出子类型

        map.put(category.getOid(), sonList);// 以键、值对的形式存到map集合中
    }

    return "qk_add";

}

 

dao里面的方法:

public List listCategoryBy(Integer id) {
  DetachedCriteria dc = DetachedCriteria.forClass(Category.class);
  dc.add(Restrictions.eq("parentid", id));
  List list = findBy(dc);
  return list;
 }

 

解决换行的问题:

在src目录下新建package:template.doubleselect,
解压struts2-core-2.1.6.jar,在里面找到
template/simple/doubleselect.ftl,复制到template.doubleselect下面,
并修改此文件,把里面的<br/>删掉。
在jsp页面<s:doubleselect/>标签里添加属性theme="doubleselect",OK!

 

原创粉丝点击