Page 1 of 1

Thymeleaf iteration status problem

Posted: Sat Aug 16, 2014 11:07 pm
by quangpld
Hi all,

I've faced an issue related to the thymeleaf iteration status:

Code: Select all

<span th:each="processOrderingCost,iteratorStatus : ${crawling_processOrderingCosts}" th:id="${'processOrderingCost' + iteratorStatus.index}" th:text="${processOrderingCost}" th:style="${!iteratorStatus.first} ? 'display:none'">0</span>


This code runs well when I put it in the templates folder (WEB-INF\templates).
But when this code runs as the email template (under WEB-INF\classes\emailTemplates) the iteratorStatus does not work. The loop still run but the iteratorStatus seems to be not exists as the template can't write the id and the style attribute for the span tag.
Does any one know about this issue?
Thanks in advance 8-)

Re: Thymeleaf iteration status problem

Posted: Sun Aug 17, 2014 3:57 am
by quangpld
I've found that this problem not relate to the iteration status variable. The actual problem is that the th:id, th:style are not written when parsing the template into HTML code while the others (like th:name, th:text) are processed as normal in email templates.
So what is the solution if I want the id or the style attribute tag when sending email?

Re: Thymeleaf iteration status problem

Posted: Sun Aug 17, 2014 4:55 am
by quangpld
The below code in emailTemplates/orderConfirmation-email.html is not also printed out the th:id attribute in the HTML:
<tr th:each="item : ${order.discreteOrderItems}" th:object="${item}" th:id="${'productRow' + item.id}" >
...
</tr>

But when using th:name instead of th:id, the name attribute is printed out in the HTML:
<tr th:each="item : ${order.discreteOrderItems}" th:object="${item}" th:name="${'productRow' + item.id}" >
...
</tr>
What is the problem here? :ugeek: :ugeek:

Re: Thymeleaf iteration status problem

Posted: Sun Aug 17, 2014 10:29 pm
by phillipuniverse
It probably has to do with the order in which the id attribute is evaluated vs the name attribute. It looks like they are both at 1000 in precendence (see id attribute name attribute) but the ID one might be added to the list after the name attribute. The th:each processor has a predence of 200 and the th:object processor has a precedence of 500 so it appears that both of them should come before id and name.

Maybe try the * syntax in th:id since you are using th:object already and see if that does anything:

Code: Select all

<tr th:each="item : ${order.discreteOrderItems}" th:object="${item}" th:id="*{'productRow' + id}" >
...
</tr>