转自:https://wenku.baidu.com/view/84fa86ae360cba1aa911da02.html

<s:bean name="com.asm.TwoSelectAction" id="ts"></s:bean>

<s:doubleselect

                            list="#ts.place"                         

                     listKey="pId" listValue="pName"
name="user.place"

                           

                            doubleList="#ts.citys[top]"

                            doubleListKey="cId"    doubleListValue="cName"

                            doubleName="user.city"

                            label="籍贯4(二级联动)">

</s:doubleselect>

它所依赖的TwoSelectAction类的主要代码如下:
package com.asm;

public class TwoSelectAction extends ActionSupport {

       private List<Province> place;

       private Map<Province,List<City>> citys;

       ...省略place 、citys中get/set方法

       public TwoSelectAction(){

              place= new ArrayList<Province>();

              citys=new HashMap<Province,List<City>> ();

             

              Province p1=new Province(1,"山东省","济南");

              Province p2=new Province(2,"山西省","太原");

              Province p3=new Province(3,"河南省","郑洲");

              Province p4=new Province(4,"河北","石家庄");

              Province p5=new Province(5,"四川","成都");

              Province p6=new Province(6,"云南","昆明");

              place.add(p1);

              place.add(p2);

              place.add(p3);

              place.add(p4);

              place.add(p5);

              place.add(p6);

             

              //山东省的市:

              City c1=new City(1,"济南");

              City c2=new City(2,"招远市");

              City c3=new City(2,"寿光市");

              List p1City=new ArrayList();

              p1City.add(c1);

              p1City.add(c2);

              p1City.add(c3);

             

              //山西省的市:

              City c4=new City(4,"太原市");

              City c5=new City(5,"大同市");

              City c6=new City(6,"晋中市");

              List p2City=new ArrayList();

              p2City.add(c4);

              p2City.add(c5);

              p2City.add(c6);

             

              //河南省的市:

              City c7=new City(7,"郑州市");

              City c8=new City(8,"卫辉市");

              City c9=new City(8,"信阳市");

              List p3City=new ArrayList();

              p3City.add(c7);

              p3City.add(c8);

              p3City.add(c9);

             

              //河北省的市:

              City c10=new City(10,"石家庄");

              City c11=new City(11,"晋州市");

              City c12=new City(12,"鹿泉市");

              List p4City=new ArrayList();

              p4City.add(c10);

              p4City.add(c11);

              p4City.add(c12);

             

             

              //四川省的市:

              City c13=new City(13,"成都");

              City c14=new City(14,"南充");

              City c15=new City(15,"绵阳");

              List p5City=new ArrayList();

              p5City.add(c13);

              p5City.add(c14);

              p5City.add(c15);

             

              //云南省的市:

              City c16=new City(16,"昆明市");

              City c17=new City(17,"安宁市");

              City c18=new City(18,"曲靖市");

              List p6City=new ArrayList();

              p6City.add(c16);

              p6City.add(c17);

              p6City.add(c18);

             

              citys.put(p1,p1City );

              citys.put(p2,p2City );

              citys.put(p3,p3City );

              citys.put(p4,p4City );

              citys.put(p5,p5City );

              citys.put(p6,p6City );

       }

}

简要分析:此实例有些繁琐,主要思想:我们的place对象主要为一级列表服务,只要理解了前面的下拉列表,这里不难理解一级列表。而二级列表中我们使用#ts.citys[top]取出的一个List对象,这样也正是下拉列表所要求的对象类型(List,Map),而top是非常关键的,它明确指出我们取出的是栈顶的对象,这样就能根据一级列表的值来动态生成这个List对象。

posted on 2016-06-15 16:24  Sharpest  阅读(156)  评论(0编辑  收藏  举报