everybody,
I have a problem with Thymeleaf, I tried to set the variable "iterator" in my for: each.
By default "iterator=0;" but if the condition is true I set the "iterator+1" but my variable is always 0 even the condition is true.
I need this "iterator" for my next block condition because if the iterator ==1 i need to something show else in my view
Here you can see my code:
<div class="col-2" th:each="t:${horaire.terrains}">
<h2 th:text="${t.nomTerrain}"></h2>
<table border="1px" >
<tr th:each="h,index : ${heures.subList(0,15)}" >
<td>
<th:block th:each="resa:${reservations}"
th:if="${resa.dateReservation eq date && resa.heureDebut eq h}">
<a>reserve</a>
<p th:with="iterator=${iterator+1} "></p>
<!--<p th:text="${iterator}"></p>-->
</th:block>
<th:block th:if="${iterator eq 0 }">
<a th:text="${h}" th:href="@{addResa(heure=${h} ,
terrain=${t.id} ,date=${date},date2=${index.index+1},
listeHeures = ${heures} )}"></a>
</th:block>
</td>
</tr>
<!--<a th:text="${h}" th:href="@{addResa(heure=${h} , terrain=${t.id}
,date=${date},date2=${index.index+1}, listeHeures = ${heures} )}">
</a>-->
</table>
</div>
Here, in my controller, you can see the variable iterator:
int iterator=0;
model.addAttribute("iterator",iterator);