我需要从 Map<String,List<HashMap<String, Object>>>
类型的映射中检索列表值在 JSP 中基于条件。条件是将映射键与 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>
上出错标签。
最佳答案
您不需要迭代映射来比较键。您只需使用大括号符号 []
即可通过动态键获取映射值,如 ${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>
关于java - 如何写 <c :if> - jSTL tag - comparing map key with struts formbean element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7667097/