ListTool - Documentation topics on: arraylist,list,listtool,velocity tools,viewtools,.

ListTool

the ListTool extends java.lang.Object and is a viewtool for working with Lists and arrays in Velocity templates. It provides a method to get and set specified elements. Also provides methods to perform the following actions to Lists and arrays:

  • Check if it is empty.
  • Check if it contains a certain element.

 

 Example uses:
$primes                     -> new int[] {2, 3, 5, 7}
$listTool.size($primes)         -> 4
$listTool.get($primes, 2)       -> 5
$listTool.set($primes, 2, 1)    -> (primes[2] becomes 1)
$listTool.get($primes, 2)       -> 1
$listTool.isEmpty($primes)      -> false
$listTool.contains($primes, 7)  -> true

Example toolbox.xml config (if you want to use this with VelocityView):
<tool>
<key>listTool</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.ListTool</class>
</tool>



As a note, to get an empty list use:

#set($myList = $contents.getEmptyList())

For complete documentation on this viewtool use the following link: ListTool