jechaviz jechaviz - 7 months ago 84
Groovy Question

Initialize a HashMap Variable in iReport

I want to create a variable $V{myMap} in iReport (3.7.3) and initialize a Map with this:

"key1":"value1","key2":"value2","key3:"value3" ...

Then in my report I will have a textField with this expression:


and i must to get


What steps i must to follow to get that?

I read here:

I want to use java.util.HashMap as variable in JasperReport

these steps to set the variable properties:

set the following properties on the variable:

Name: myMap
Variable class: java.util.HashMap()
Reset type: None
Calculation: System
Variable expression: new java.util.HashMap()

But what about initialize it?

I know i can use groovy and use maps like in this article:

But i dont' know which steps to follow.

Thanks in advance for share your knowledge!


This is the method to create the variable

<variable name="myMap" class="java.util.HashMap" resetType="None" calculation="System">
    <variableExpression><![CDATA[['key1':'value1', 'key2':'value2', 'key3':'value3']]]></variableExpression>

Then for use it:


Will get