Doubt with Expression Language JSTL JSP

Asked

Viewed 95 times

1

How to verify the value that is arriving in EL, in the listPedidos variable of items ?

<c:forEach var="pedido" items="${listPedidos}" varStatus="id">

    <c:if test="${pedido.tipoPedido == 'MESA' }">
        <tr>
            <td>${id.count}</td>
            <td>${pedido.mesa.numero}</td>
            <td>${pedido.nomeCliente}</td>
            <td>${pedido.valorTotal}</td>
            <td> <fmt:formatDate type="time" value="${pedido.dtPost.time}" /> </td>
         </tr>
    </c:if>

  • Could be, just to see what comes in this variable.

1 answer

0

It’s not clear.

If you want to know the value of listPedidos just call a ${listPedidos} anywhere in the document.

To loop only if listPedidos is neither null nor empty, you can use the operator empty to test the condition:

<c:if test="${empty listPedidos}">
  Nenhum Pedido.
</c:if>

<c:if test="${not empty listPedidos}">
   <c:forEach var="pedido" items="${listPedidos}" varStatus="id">

    <c:if test="${pedido.tipoPedido == 'MESA' }">
        <tr>
            <td>${id.count}</td>
            <td>${pedido.mesa.numero}</td>
            <td>${pedido.nomeCliente}</td>
            <td>${pedido.valorTotal}</td>
            <td> <fmt:formatDate type="time" value="${pedido.dtPost.time}" /> </td>
         </tr>
    </c:if>
</c:if>

Can use !empty instead of not empty, if you prefer.

Can use <c:choose> also, as in that question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.