Kleber Mota
Kleber Mota

Reputation: 9095

Iterating two list in parallel with thymeleaf

In my current spring-boot project, I have this thymeleaf code:

<th:block th:each="item : ${menu}">
...
              <a th:href="@{/__${menu2}__/listagem}">
                  <i class="icon-asterisk"></i>
                  <span th:utext="${item}"></span>
              </a>
...
<th:block>

where I am trying iterate the two lists (menuand menu2) in a single loop th:each. For menu2 I try this:

${menu2[itemStat.index]}

but I am getting the error:

org.springframework.expression.spel.SpelEvaluationException: EL1012E:(pos 5): Cannot index into a null value

What is the right way to access this second list inside the loop?

UPDATE

Upvotes: 0

Views: 3083

Answers (1)

Aeseir
Aeseir

Reputation: 8434

Not having more details i'm making big assumptions when providing this answer.

<block th:each="item,itemStat : ${menu}">
<span th:text="*{menu2[__${itemStat .index}__].something}"></span>  // assuming its a object that has parameter called somethin
</block>

Your menu 2 list i believe is empty hence the null too.

Upvotes: 3

Related Questions