java - 如何写 <c :if> - jSTL tag - comparing map key with struts formbean element

标签 java jsp struts jstl

我需要从 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/

相关文章:

java - 如何阻止 Maven 弄乱我的目录布局及其属性?

Java使用通配符正则表达式匹配字符串来查找<H1>标签

javascript - 当 Controller 返回空结果时,如何在jsp中显示空值?

java - <fmt :message key ="key"/>? 有简写吗

java - 如何从struts bean中获取值?

java - 如何使用 Java 重定向到 Pentaho 用户控制台?

java - 我怎样才能更好地构建这段代码?

java - Python 相当于 Java 抽象类吗?

java - 使用 deploy 命令在 glassfish 上部署 maven 项目

java - 我可以在这里使用什么描述性变量名称?