2012-02-03 23 views
6

sto cercando questo, ma la sua intenzione di parte else sempreJSP operatore mod non funziona

<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> 

Cosa c'è di sbagliato in questo?

+2

Hai provato con '$ {(counter.count mod 2) == 0} '? –

+0

sì, funziona ora .. Grazie JB – user965884

risposta

19

Si potrebbe anche usare ${counter.count % 2 == 0}

-2

JSTL Separato da html + plus non la matematica per voi tipi artistici

<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}