We've got the following code:
<div th:each="client : ${clients}">
<div th:each="purchase : ${client.purchases}">
<div th:each="product : ${purchase.products}">
<span th:text="${product.price}"></span>
<!-- <span id="2" th:text="${#aggregates.sum(products.{price})}"> </span> -->
<!-- <span id="2" th:text="${#aggregates.sum(products.![price])}"> </span> -->
</div>
</div>
</div>
The output is:
5.25
4.20
If I uncomment the first comment, I get error
Exception evaluating SpringEL expression: "#aggregates.sum(products.{price})" (clients/clients:84)
If I uncomment only the second comment, I get error:
Exception evaluating SpringEL expression: "#aggregates.sum(products.![price])" (clients/clients:85)
I tried to use http://demo-dspace-cris.cineca.it/bitstream/123456789/26/1/usingthymeleaf.pdf
I am using thymeleaf 2.1.4
IT WORKS !
I should use:
<span id="2" th:text="${#aggregates.sum(purchase.products.![price])}"> </span>
Thymeleaf works thanks to a DOM processing engine and a series of processors —one for each type of node that needs to apply logic— that modify the document’s DOM tree in order to create the results you expect by combining this tree with your data.
Let's construct the templates piecemeal based on what type of errors we can display. 3.1. Displaying Field Errors Thymeleaf offers an inbuilt field.hasErrors method that returns a boolean depending on whether any errors exist for a given field. Combining it with a th:if we can choose to display the error if it exists:
In this case, if $ {condition} is false, null will be returned, and thus no removal will be performed. Thymeleaf calls local variables those variables that are defined for a specific fragment of a template, and are only available for evaluation inside that fragment. An example we have already seen is the prod iter variable in our product list page:
It is better suited for serving XHTML/HTML5 in web applications, but it can process any XML file, be it in web or in standalone applications. The main goal of Thymeleaf is to provide an elegant and well-formed way of creating templates.
I figured it myself after posting here !
<div th:each="client : ${clients}">
<div th:each="purchase : ${client.purchases}">
<span id="2"
th:text="${#aggregates.sum(purchase.products.![price])}"> </span>
<div th:each="product : ${purchase.products}">
<span th:text="${product.price}"></span>
</div>
</div>
</div>
output:
9.45
5.25
4.20
site that helped me a lot: http://forum.thymeleaf.org/aggregates-with-Spring-td3767446.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With