AndreFontaine
AndreFontaine

Reputation: 2584

Foreach in jstl c tag

I´m using jstl in jsp, creating a object result from a DTO, when I use it in this way:

<c:if test="${not empty result.billedConsumptionActive}">
    <p><c:out value="${result.billedConsumptionActive}"></c:out></p>
</c:if>

This return and print:

ConsumptionDTO [consumptionHour00=37.6, consumptionHour01=null, consumptionHour02=null, consumptionHour03=50, consumptionHour04=null, consumptionHour05=null, consumptionHour06=12.5, consumptionHour07=null]

But when I try to use it in a foreach statement:

<c:if test="${not empty result.billedConsumptionActive}">
    <c:forEach var="window" items="${result}">
        <td><c:out value="${result.billedConsumptionActive}"/></td> 
    </c:forEach>
</c:if>

I got an error, and I cant explain why. There's another way to call items="${result}??

Upvotes: 0

Views: 471

Answers (1)

Paul Vargas
Paul Vargas

Reputation: 42020

Try this:

<c:if test="${not empty result.billedConsumptionActive}">
    <c:forEach var="window" items="${result.billedConsumptionActive}">
        <td><c:out value="${window}"/></td> 
    </c:forEach>
</c:if>

Upvotes: 1

Related Questions