Hashmap and Arraylist in Velocity

Posts: 8
Joined: Wed Feb 08, 2017 10:16 am

Hashmap and Arraylist in Velocity

Postby dbosman » Mon Feb 27, 2017 9:19 am



an example is showed how to use maps and lists in Velocity:

#set( $monkey.Say = ["Not", $my, "fault"] ) ## ArrayList
#set( $monkey.Map = {"banana" : "good", "roast beef" : "bad"}) ## Map

Unfortunately this does not work in 2016 SR1.

1. Which Velocity version is Polarion 2016 SR1 using?

I tried the following workaround:

1.doc: $document <BR>
2.dc: $document.getClass() <BR>
3.class: $document.getClass().forName("java.util.ArrayList") <BR>
4.lst: $document.getClass().forName("java.util.ArrayList").newInstance() <BR>

Unfortunately step 3 fails.

How does one create a ArrayList or HashMap in Velocity?

Posts: 3
Joined: Tue Sep 23, 2014 8:40 am

Re: Hashmap and Arraylist in Velocity

Postby enkelmann » Fri Mar 16, 2018 6:56 pm

Polarion needs a bit of extra work, but what you want can be done.

To get maps work, you need to install the "Wiki Scripting Tools Extension" http://extensions.polarion.com/extensions/83-wiki-scripting-tools.

With that in place, you can do:

Code: Select all

#set ($monkeySay = ["Not", $me, "fault"] ) ## ArrayList
#set ($monkeyMap = $objectFactory.newMap() )  ## Map
#set ($trash = $monkeyMap.put("banana", "good"))
#set ($trash = $monkeyMap.put( "roast beef", "bad"))

$monkeySay.class - $monkeySay<br>
$monkeyMap.class - $monkeyMap<br>

Which gives the desired result:

Code: Select all

class java.util.ArrayList - Test.Not, admin, fault
class java.util.HashMap - {banana=good, roast beef=bad}


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: No registered users and 2 guests