chellapandi k chellapandi k - 9 days ago 6
Java Question

FreeMarker arithmetic operations in list iteration java

I need to do some arithmetic operations in freemarker template. I have a list of objects and i need to apply the arithmetic operation like below...

<#list order.orderDetails as orderDetail>
<tr>
<#assign orderTotal=${orderDetail.quantity}*${orderDetail.price}>
<td>${orderDetail.product.productName}</td>
<td>${orderDetail.quantity}</td>
<td>${orderDetail.price}</td>
<td>orderTotal</td>
</tr>
</#list>


I need order total value using this calculation but it doesn't work. It shows


error in syntax. assign tag is not accepting this kind of value injection.

Answer

Perform arithmetic like this:

<#assign orderTotal=orderDetail.quantity * orderDetail.price>

Refer to your variable like this:

<td>${orderTotal}</td>

Or just:

<td>${orderDetail.quantity * orderDetail.price}</td>
Comments