Velocity DisplayTool has a useful method:
$display.list($list)
That will format a collection or array into the form ‘A, B and C’.
The problem is lets say I have an ArrayList of objects, how do I output a specific object field instead of the whole object? For example the regular loop would look like this:
#foreach($obj in $list) ${obj.title} #end
For now I just made obj.toString() to return obj.title, but what if I will need another field?
Thanks.
UPDATE Ended up implementing this method myself and committing it to DisplayTools. So it is a part of Tools 2.0 now.
You might consider extending the DisplayTool to support this. Take a look at the SortTool, it allows you to sort on properties. Copying code from there should give you a good start toward adding this to DisplayTool. And if you do this and feel like sharing, let us know over on the dev@velocity.apache.org list. Heck, if i’m bored some day, i might do this myself.