Doubt with Expression Language JSTL JSP

1

How to check the value that is arriving in the EL, in the variable listItems for 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>

    
asked by anonymous 21.07.2017 / 17:25

1 answer

0

It's unclear.

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

To loop only if listPedidos is not null or empty, you can use the 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>

You can use !empty instead of not empty , if you prefer.

You can also use <c:choose> , such as on this question .

    
21.07.2017 / 18:38