循环遍历EL中项目的所有属性

时间:2013-08-08 14:45:40

标签: jsp jstl el

BalusC可能会为我解答这个问题。

我有一个字符串列表,我将其设置为请求对象中的属性。每个字符串代表一个表头,我将在页面上打印出来。

然后,我将为每个其他类型的“进程”对象包含一个jsp。每个流程对象都具有相同的属性,但有些属性已填充,有些则未填充。

这是目标:对于每个进程,遍历列名列表中的每个字符串。如果此进程中与该字符串匹配的属性具有值,则我想显示该值,否则我将该单元格留空。

基本上,我要求的是一种在EL和JSTL中进行递归的方法,这样我就可以检查一个过程中的每个属性。

如果其中任何一个没有意义或者您需要更多扩展,请询问。

修改

<c:forEach items="${colNames}" var="cName"><%--colNames is the list of strings --%>
    <c:forEach items="${item.values}" var="value"><%--item is the process whose attributes I want to iterate through --%>
            <c:if test="item has attribute that matches cName">
                <td><c:out value="${value}"/></td><%--if item has an attribute that matches the string in the list, then I want to print out the value of that attribute--%>
            </c:if>
    </c:forEach>
</c:forEach>

1 个答案:

答案 0 :(得分:0)

试试这个:

<c:forEach items="${colNames}" var="cName">
    <c:forEach items="${item.values}" var="value">
            <c:choose>
               <c:when test="${cName==value}">
                   <td><c:out value="${cName}"/></td>
               </c:when>
               <c:otherwise>
                   <td></td>
               </c:otherwise>
            </c:choose>
    </c:forEach>
</c:forEach>
相关问题