Jump to content
We've recently updated our Privacy Statement, available here ×

Pass multiple parameters


malliboy

Recommended Posts

To pass parameters, I can do the following.

Map parameters = new HashMap();
parameters.put("imageDir", imageDir);

What if I wanted to pass 100 strings? Do I need to write 100 statements like the one above? Or can I pass them as a list or something? If so, how do I access it from my jrxml?

Thanks,

Malliboy.

 

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

You can put a List object in your parameter map. Then you have just to declare a parameter like this in your jrxml file:
<parameter name="imageDir" isForPrompting="false" class="java.util.List"/>

To use it in an expression you can write for example:
$P{imageDir}.get(0)

Link to comment
Share on other sites

If you use a List or a Collection, we can refer it only by the index. I was looking for a key-value pair. Yes, adding them to the 'parameters' hashmap serves the purpose, but again, if I need to pass 100 strings, I need to explicitly include the parameters in the jrxml. I was looking for a solution and found one - Another hashmap within 'parameters'.

HashMap myMap = new HashMap();
myMap.put("1", "A");
myMap.put("2", "B");
myMap.put("3", "C");

Map parameters = new HashMap();
parameters.put("myMap", myMap);

In the jrxml, fetch values using '$P{myMap}.get("1")'. The advantage is that we don't to specify A, B and C in the parameter section of the jrxml. Looks like anything - Tree, Map can be used. Hope that helped. :)

 

 

 

Link to comment
Share on other sites

  • 3 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...