Tomek Nowak
Tomek Nowak

Reputation: 123

Thymeleaf iterating over a list

I want to iterate over a list using thymeleaf. My code looks like this:

<ol th:each="test: ${tests}">
    <li th:text="${test.toString()}"></li>
</ol>

At this moment, tests Set contains 2 elements, which have a toString() representation, respectively test1 and test2

My output in html looks like this:

1.test1
1.test2

I am wondering why do both of them have the number 1, instead of 1 and 2?

Upvotes: 2

Views: 938

Answers (1)

sourcloud
sourcloud

Reputation: 124

You are creating an ordered list for each item instead of listitems.

This should work:

<ol>
    <li th:each="test: ${tests}" th:text="${test.toString()}"></li>
</ol>

Upvotes: 3

Related Questions