Using th:each loop variable in OGNL expression

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

Using th:each loop variable in OGNL expression

Nibsi

Hello everyone. I'm new to Thymeleaf.

I'm wondering if there is an elegant way to use a th:each loop variable's current value inside an OGNL expression. Right now I'm selecting the current value with th:object, and then referring to it in my expression with #object:

<ul>
  <li data-th-each="conversation: ${conversations}" data-th-object="${conversation}">
    <a data-th-href="${mvc.uri('conversations.get', #{'id': #object.id})}" data-th-text="*{topic}"></a>
  </li>
</ul>

This would become very tedious though, as I expect to refer to loop variables a lot from OGNL expressions.

Is there a shorthand to automatically select the loop variable? Is there a shorter expression I can use to refer to my conversation variable from OGNL other than through #object? I feel that I am missing something.

Other comments on my code snippet are very welcome.

P.S. I'm not using @{conversations/{id}(id=*{id})} for the link, because I want to use a URI reference (conversations.get) rather than a path to refer to my controller action.

Reply | Threaded
Open this post in threaded view
|

Re: Using th:each loop variable in OGNL expression

Nibsi