2011-10-05 40 views
1

我需要根據條件從JSP中的Map<String,List<HashMap<String, Object>>>類型的地圖中檢索列表值。條件是比較map key和formbean變量。現在,我正在做多級迭代。首先,我迭代映射來檢索鍵和一個內部迭代循環來檢索列表值。如何編寫<c:if> - jstl標籤 - 比較map key和struts formbean元素

到目前爲止,我有這樣的

<c:forEach items="${addRatingExceptionForm.ratingsMap}" var="entry"> 
    <c:set var="key" value="${entry.key}"/> 
    <jsp:useBean id="key" type="java.lang.String" /> 
    <c:if test= '<%= key.equalsIgnoreCase(addRatingExceptionForm.getRatingElementDropdown()) %> ' > 
    <c:forEach items="${entry.value}" var="item"> 
     <li> 
     <input type="checkbox" id="addRatingException_timeline_earlyAsn" value="${item.RatingInstanceValue}" class="ajaxContentTrigger method_Load_exceptionType ajaxLoadingTrigger|addRatingException_exceptionType clearErrors"/> 
     <label for="addRatingException_timeline_earlyAsn">${item.RatingInstanceValue}</p></label> 
     </li> 
    </c:forEach> 
    </c:if> 
</c:forEach> 

但它在<c:if>標籤錯誤。

+1

的功能要求是不理解。請詳細闡述功能需求和/或發佈* real *僞代碼而不是失敗的代碼嘗試,因爲這些無助於理解您實際*想要的內容。 – BalusC

+0

'<%= $ {entry.key} .equalsIgnoreCase(addRatingExceptionForm.getRatingElementDropdown())%>' - 就像一個旁註:'<%=' and '%>'之間的scriptlet部分*在表達式之前執行* $ {entry.key }'被評估,因此該代碼無法工作。 – Thomas

+0

我需要從基於條件的jsp中Map >>的映射檢索列表值。條件是比較map key和formbean變量。現在,我正在做多級迭代。首先,我迭代映射來檢索鍵和一個內部迭代循環來檢索列表值。 – aditya86c

回答

0

您不需要遍歷映射來比較鍵。您只需使用大括號[]即可通過動態鍵獲取地圖值,如${map[key]}

所以,這應該這樣做:

<c:forEach items="${addRatingExceptionForm.ratingsMap[addRatingExceptionForm.ratingElementDropdown]}" var="item"> 
    <li> 
    <input type="checkbox" id="addRatingException_timeline_earlyAsn" value="${item.RatingInstanceValue}" class="ajaxContentTrigger method_Load_exceptionType ajaxLoadingTrigger|addRatingException_exceptionType clearErrors" /> 
    <label for="addRatingException_timeline_earlyAsn">${item.RatingInstanceValue}</p></label> <!-- wtf is that </p> doing there? --> 
    </li> 
</c:forEach>