2012-02-03 16 views
6

Próbuję to, ale jej będzie inny części zawszeJSP mod operator nie działa

<c:forEach items="${records}" var="field" varStatus="counter"> 

    <c:choose> 
     <c:when test="${counter.count mod 2 == 0}"> 
      <div class="classEven"> 
     </c:when> 
     <c:otherwise> 
      <div class="classOdd"> 
     </c:otherwise> 
    </c:choose> 
     sample text here 

     </div>   

</c:forEach> 

Co z tego?

+2

Czy próbowałeś z '$ {(counter.count mod 2) == 0} '? –

+0

tak, teraz działa. Dzięki JB – user965884

Odpowiedz

19

Można również użyć ${counter.count % 2 == 0}

-2

separacji JSTL z html + Plus nie matematyka dla was pretensjonalnymi typów

<c:set var="row" value="Even" /> 
<c:forEach items="${records}" var="field" varStatus="counter"> 
<c:choose> 
     <c:when test="${row eq 'Odd'}"> 
      <c:set var="row" value="Even" /> 
     </c:when> 
     <c:otherwise> 
      <c:set var="row" value="Odd" /> 
     </c:otherwise> 
    </c:choose> 

     <div class="class${row}"> 

     sample text here 

     </div>   


</c:forEach> 
1
test = ${counter.index mod 2 == 0} 
Powiązane problemy