I am using velocity for email templates in my java/spring 3 app.
How could I get the size of an ArrayList added to the model from within the template.
We can find the size of an array using the sizeof() operator as shown: // Finds size of arr[] and stores in 'size' int size = sizeof(arr)/sizeof(arr[0]);
Every array has an in-built length property whose value is the size of the array. Size implies the total number of elements that an array can contain. The length property can be invoked by using the dot (.)
The size of an array object is always equal to the second template parameter used to instantiate the array template class (N). Unlike the language operator sizeof, which returns the size in bytes, this member function returns the size of the array in terms of number of elements.
Approach 1: The obvious approach: Run and check. Run Velocity against the template to be checked. Look at the output and see if it is what you desired. This must be the most primitive testing approach, but most people nowadays are too lazy and want this done by the computer.
I've never used Velocity, but its VTL reference guide says that calling a method is done using $customer.getAddress()
or ${purchase.getTotal()}
. So I would use ${myArrayList.size()}
.
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