Problem with Counter in JSTL or change for a for (int i)

0

I need to carry a variable counter in an html using JSTL because the JSTL uses a Foreach instead of a for (int i ..)

I tried with: Da error

  <c:set var="i" value="-1"/>
     <c:forEach items="${finalmente}" var="dato"> 
         <c:set var="i" value="${i=i+1}"/>
          <c:out value="${i}"/>
      </c:forEach>

Paint literally "i ++"

      <c:set var="i" value="-1"/>
         <c:forEach items="${finalmente}" var="dato"> 
             <c:set var="i" value="i++"/>
              <c:out value="${i}"/>
          </c:forEach>

It does not do anything:

                 <fmt:parseNumber var = "id" type = "number" value = "-1" />
                        <c:forEach items="${finalmente}" var="dato"> 
                              <fmt:parseNumber var = "id" type = "number" value = ${id+1} />
                                    <c:out value="${id}"/>
                         </c:forEach>

I need some way to keep an accountant. I also have the option of going through Spring MVC the Array "finally" without having to use it, but I do not know how to do it with Spring

The Array sent them to view with:

vista.addObject("finalmente", ArrayOrdenado);

Any of the 2 options is worth me: Keep a counter with JSTL or go through "finally" with a for (int i) in the html.

Thanks

    
asked by EduBw 12.03.2018 в 22:24
source

1 answer

2

The correct way is like this:

<c:set var="i" value="1"/>
<c:forEach items="${finalmente}" var="dato">
  <c:out value="${i}"/>
  <c:set var="i" value="${i+1}"/>
</c:forEach>

Since in JSTL can not be done with the post increment, what you should do is re-set the data (value) to the variable.

    
answered by 12.03.2018 / 22:36
source