最近用struts2 开发的时候实现了动态的doubleselect菜单。在这里共享一下!
jsp:
<STYLE type="text/css">
.doubleselect br {
display: none;
}
</STYLE>
<div class="doubleselect">
<s:doubleselect list="gzzType" listKey="gzzlx"
listValue="gzzmc1" doubleName="jcd.sId"
doubleList="gzzMap.get(top.gzzlx)" doubleListKey="sid"
doubleListValue="gzzmc1" theme="simple">
</s:doubleselect>
java Action:
/**
*
*/
private static final long serialVersionUID = 1L;
private GzzLx gzz;
private List<GzzLx> gzzs;
private List<GzzLx> gzzType;
Map<Integer, List<GzzLx>> gzzMap;
private JiancedianService jcdService = new JiancedianService();
private Jiancedian jcd;
private List<Jiancedian> jcds;
private String gzzId;
private Login login;
private String stationGup;
private String jcdId;
public JiancedianAction() {
login = (Login) ActionContext.getContext().getSession().get("user");
stationGup = login.getStationGup();
}
public String selectJcd() throws Exception {
this.jcds = jcdService.findById(jcd);
doubleListValues();
return SUCCESS;
}
public String updateJcd() throws Exception {
jcdService.update(jcd);
selectJcd();
return SUCCESS;
}
public String selStaionName() throws Exception {
doubleListValues();
return SUCCESS;
}
public String selectByIdjcd() throws Exception {
this.jcd = jcdService.selectByIdjcd(jcdId);
selectJcd();
return SUCCESS;
}
public String resetJcd() throws Exception {
this.jcd = null;
doubleListValues();
return SUCCESS;
}
private void doubleListValues() {
gzzMap = new HashMap<Integer, List<GzzLx>>();
gzzType = new ArrayList<GzzLx>();
for (int i = 1; i <= 4; i++) {
gzzs = new ArrayList<GzzLx>();
gzz = new GzzLx();
gzzs = jcdService.selStaionName(stationGup, i);
if (!gzzs.isEmpty()) {
gzz.setGzzlx(i);
if (i == 1) {
gzz.setGzzmc1("1");
} else if (i == 2) {
gzz.setGzzmc1("2");
} else if (i == 3) {
gzz.setGzzmc1("3");
} else {
gzz.setGzzmc1("4");
}
gzzType.add(gzz);
gzzMap.put(i, gzzs);
}
}
}