not sure why, but th:each is not iterating my list on divs

classic Classic list List threaded Threaded
5 messages Options
Nim
Reply | Threaded
Open this post in threaded view
|

not sure why, but th:each is not iterating my list on divs

Nim
This post was updated on .
This is my code:

<div th:each="acc:${List}">
      <div class="span11 offset1" th:text="'Le Moneys'">Le Moneys</div>
      <div class="span12 pagination-right" th:text="${#numbers.formatDecimal(acc.balance,3,'COMMA',2,'POINT')}">
           4,252.00</div>
</div>

For some reason it doesn't work. Does th:each not work with divs? List isn't empty, as per run-time so that's definitely not it.
Reply | Threaded
Open this post in threaded view
|

Re: not sure why, but th:each is not iterating my list on divs

Emanuel
Administrator
I noticed your ${List} is using a capital L.  Is your context variable also "List", or is it "list"?  I just tried making a list set to "list" but referred to in the th:each with a capital L, and Thymeleaf didn't loop through my list, and it didn't throw an error either.
Nim
Reply | Threaded
Open this post in threaded view
|

Re: not sure why, but th:each is not iterating my list on divs

Nim
Oops yea it's in lower case in the actual code, but it still doesn't iterate divs for some reason. Does it work with lower case list on your end? I'm using twitter bootstrap btw.
Reply | Threaded
Open this post in threaded view
|

Re: not sure why, but th:each is not iterating my list on divs

Emanuel
Administrator
I got it to work on a very small example, which was:

Servlet:

context.setVariable("list", new int[]{10000, 2346235, 2313, 1231});


HTML:

<div th:each="num: ${list}">
  <div th:text="${#numbers.formatDecimal(num, 3, 'COMMA', 2, 'POINT')}"></div>
</div>

When list had a capital L in the HTML, then it didn't iterate, but it didn't throw an error either.

So it should iterate...  You haven't added another "list" item to the context, or redefined "list" in the HTML code before-hand?
Nim
Reply | Threaded
Open this post in threaded view
|

Re: not sure why, but th:each is not iterating my list on divs

Nim
Oops I just realized my mistake, the variable i was sending was called something completely different. Silly me. Thanks for the help though.