你妹的,Doubleselect标签,用了半天,还没搞清楚怎么回事,求解
使用doubleselect标签实现2个下拉框的联动,在自己构建数据的时候,就格式很好的展现。但是在从数据库中取数据出来展现的时候,总是展现第一级,奶奶的,第二级从来没有出现过,神马原因,我自己都不清楚。
大家帮我找哈原因。
下面贴出关键代码。
从数据库中取数据的方法。
/**
* 获得一级分类列表
* @param enterpId
* @param catelogType
* @return
* @throws Exception
*/
public List<TbCatelog> getFirstCatelogList(int enterpId,int catelogType)throws Exception{
Map<String, Object> argsMap = new HashMap<String, Object>();
argsMap.put("enterpId", enterpId);
argsMap.put("catelogType", catelogType);
return this.getListByQuery("GET_FIRST_CATELOGLIST_BYENTERPID_CATELOGTYPE", argsMap);
}
/**
* 获得二级分类映射对象
* @param catelogType
* @return
* @throws Exception
*/
public Map<Integer, List<TbCatelog>> getSecondCatelogMap(int enterpId,int catelogType) throws Exception{
List<TbCatelog> firstCatelogList = new ArrayList<TbCatelog>();
TbCatelog catelog = new TbCatelog();
catelog.setCatelogid(0);
catelog.setCatelogname("请选择一级分类");
firstCatelogList.add(catelog);
firstCatelogList = this.getFirstCatelogList(enterpId, catelogType);
Map<Integer, List<TbCatelog>> subCatelogMap = new HashMap<Integer, List<TbCatelog>>();
if (firstCatelogList!=null) {
for (TbCatelog tbCatelog : firstCatelogList) {
if (tbCatelog!=null) {
List<TbCatelog> subCatelogList = new ArrayList<TbCatelog>();
TbCatelog subCatelog = new TbCatelog();
subCatelog.setCatelogid(0);
subCatelog.setCatelogname("请选择二级分类");
subCatelogList.add(subCatelog);
subCatelogList = this.getSubCatelogList(tbCatelog.getCatelogid());
subCatelogMap.put(tbCatelog.getCatelogid(), subCatelogList);
}
}
}
return subCatelogMap;
}
下面是Action中加载数据的方法
private List<TbCatelog> selectCatelogList = new ArrayList<TbCatelog>();
private Map<Integer, List<TbCatelog>> mapCatelogMap = new HashMap<Integer, List<TbCatelog>>();
/**
* 加载分类选择数据
* @return
*/
public String loadCatelogSelect(){
if (enterpId!=0) {
try {
//加载一级分类列表
//加载第二级分类列表MAP
selectCatelogList = catelogService.getFirstCatelogList(enterpId, 0);
mapCatelogMap = catelogService.getSecondCatelogMap(enterpId, 0);
return Const.SELECT_OK;
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
public List<TbCatelog> getSelectCatelogList() {
return selectCatelogList;
}
public void setSelectCatelogList(List<TbCatelog> selectCatelogList) {
this.selectCatelogList = selectCatelogList;
}
public Map<Integer, List<TbCatelog>> getMapCatelogMap() {
return mapCatelogMap;
}
public void setMapCatelogMap(Map<Integer, List<TbCatelog>> mapCatelogMap) {
this.mapCatelogMap = mapCatelogMap;
}
下面是doubleselect的标签填写
--------------------编程问答-------------------- 贴<s:debug>代码
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<style>
.doubleselect br {
display: none;
}
</style>
</head>
<body>
<s:form name="doubleSelectForm" action="loadNewsCatelogAction">
<div class="doubleselect">
<s:doubleselect formName="doubleSelectForm" list="selectCatelogList"
listKey="catelogid" listValue="catelogname"
doubleList="mapCatelogMap.get(top.catelogid)" doubleListKey="catelogid"
doubleListValue="catelogname"
doubleName="doubleSelectEntity.subCatelogId" />
</div>
</s:form>
</body>
</html>
看你页面能取到什么值
补充:Java , Java EE