java - Apache Velocity "generic" macro -


we using velocity generate report of results of processing recurring task. pass in list of processed packages , associated results.

#foreach($pkg in $packages)   <tr>     <td>$pkg.name</td>     <td>$pkg.numitems</td>     <td>$pkg.processingtime</td>     <td>$pkg.numerrors</td>   </tr> #end 

now want include summary, i.e. want sum different results. though using "generic" macros can pass list and name of attribute should summed up. like:

#macro(sum $list $attribute) #set($total=0) #foreach($item in $list) #set($total =$total+$item.$attribute) #end $total #end 

but not work - somehow possible write "generic" macro calculate sum of attribute of items of list or have either calculate them totals before calling velocity or calculate them each attribute individually?

velocity isn't meant used scripting language. so

#set( $total = $total+$item.$attribute ) 

will not work hope. if $item class had get(string attribute) method, do:

#set( $total = $total+$item.get($attribute) ) 

otherwise, need hack rendertool , mathtool velocitytools project.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -