日期:2014-05-17  浏览次数:20747 次

jstl的forEach嵌套问题,三层
如题:jstl嵌套问题 

先说说思路:

map装的key是项目,value是一个List

这个List是有map组成,key为幢,value为List

里面这个List是户信息,key为户,value为户List

现在后台代码如下

Java code


listOfZone = new ManagementProjectInfoBean().getManagementProjectInfoListBySql(str);//临时存放小区下项目
        for(int i=0; i<listOfZone.size(); i++) {
            //每个项目下的幢
            rIBean.existBuilds(((ManagementProjectInfoView)listOfZone.get(i)).getId(), listOfTemp, Constants.DELETE_MANAGEMENTPROJECTINFO);
            for(int j=0; j<listOfTemp.size(); j++) {
                List houseList = new ArrayList();
                RelInfo rInfo = (RelInfo)listOfTemp.get(j);//
                BuildView bView = new BuildTabBean().getBuildTabView(rInfo.getBuildId());
                int total = new HouseTabBean().getHousePositionInfo(houseList, bView.getId());
                mapOfTemp.put(bView, houseList);
                sumOfPjtSelf += total;        
                listOfPjt.add(mapOfTemp);
            }
            sumOfPjt += sumOfPjtSelf;
            mapOfPjt.put(((ManagementProjectInfoView)listOfZone.get(i)), listOfPjt);
        }
        sumOfAll = sumOfPjt + sumOfZone;
        Collections.sort(new ArrayList(mapOfPjt.keySet()));





其中,listOfTemp为所有的幢id的List

-------------------------------------

jsp代码(jstl)如下

Java code


<table border=0 cellpadding="5" cellspacing="1" class="table_huei"  >
<tr class="tr_data1">
   <td colspan="2" class="tr_title2" align="center">${zv.name}:项目信息</td>
   <td width=4%>${sumOfPjt}</td>
</tr>
<!-- map start-->
<c:forEach items="${mapOfPjt}" var="item" >
<tr class="tr_data1">
   <td colspan="2" class="tr_data3" align="center">${item.key.projectName}:项目信息</td>
   <td width=4%>${sumOfPjt}</td>
</tr>
    <c:forEach items="${item.value}" var="item1" >
    <tr class="tr_data1">
       <td width=17% align="right">${item1.key.broough}${item1.key.road}${item1.key.tabletNum}</td>
       <td width=79%><c:forEach items="${item1.value}" var="item11" >
          ${item11.cellNum}单元${item11.floorNum}${item11.maproomNum} |
       </c:forEach></td>
       <td width=4%><c:out value="${fn:length(item1.value)}"></c:out></td>
    </tr>
    </c:forEach>
</c:forEach>
<!-- map end-->
</table>





目前估计是jsp出错,执行到 <c:forEach items="${item.value}" var="item1" >
 就跳到文件末尾了,调试了半天不见结果,没思路了

望高人能帮忙看看 

出现这样一个错误

 com.pkpm.houseManager.dataView.BuildView cannot be cast to java.lang.String



------解决方案--------------------
List list1 = new ArrayList(); 
list.add(xxxx)
List list2 = new ArrayList(); 

Map map = new HashMap(); 
map.put("key1",list1); 
map.put("key2",list2); 

request.setAttribute("maps",map);

jsp:

<c:forEach var="map" items="${maps}"> 
<c:out value='${map.key }'/><br> 
 
<c:forEach var="each" items="${map.value }"> 
<c:out value='${each.id }'/><br> 
<c:out value='${each.name }'/