Increase JSTL value

0

I have a table that shows the values of a select. Each field is accompanied by a numerical value that refers to each of the lines that the table has. But I'm not able to make them grow.

<tbody>
   <c:set var = "contador" value = "1" scope="page"/>
   <c:forEach items="${list}" var="actividad">
      <tr>
         <th scope="row">
            <c:set var="contador" value="${contador + 1}" scope="page"/>
         </th>
         <td>${actividad.actividad}</td>
         <td>${actividad.hora}</td>
      </tr>
   </c:forEach>
</tbody>
    
asked by Eduardo 19.03.2018 в 09:20
source

1 answer

1

It seems to me that when you do <c:set var = "contador" value = "1" scope="page"/> , the value of 1 is recognized as a String.

Try with:

<c:set var = "contador" value = "${1}" scope="page"/>

Update:     Now that we know that what you want is to show the counter, you can use

<c:out value = "${ }" /> and varStatus = " " :

   <c:forEach items="${list}" var="actividad" varStatus="numero">
      <tr>
         <th scope="row">
             <c:out value = "${numero.count}"/>
         </th>
         <td>${actividad.actividad}</td>
         <td>${actividad.hora}</td>
      </tr>
   </c:forEach>

If you use ${numero.index} it starts counting from 0 . If you use ${numero.count} you count from 1

    
answered by 19.03.2018 / 09:30
source