EricHolsinger.com

Icon

This is where you get the spin on Eric Holsinger.

Instantiating an iReport Collection parameter from an Array in one line

While working with iReport, I wanted to test my report with a default Collection value for my Hibernate Query.

The HQL is something like this,


SELECT person.fullName as personName
FROM Person person
WHERE person.id in ($P{people})

The Person.id is a long.
The report parameter $P{people} is a Collection.

To add a default value for testing, I had to rediscover instantiating a Collection from an Array. I was trying to find Arrays.asList(), and the like, but couldn’t remember it at the time.

While searching for what I needed, I found a lot of forums where people would ask how to do instantiation of a Collection from an Array without looping.

If you already have an array (perhaps named ‘myArray’), you could do something like the following.

new ArrayList(Arrays.asList(myArray));

In my case, I didn’t have an array, yet. I also wanted to initialize the array, too. Initializing an array of objects is easy enough.

new Long[] {new Long(521), new Long(423)};

So, combining the two, my default parameter would get


new ArrayList(Arrays.asList(
new Long[] {new Long(521), new Long(423)}
));

Hopefully this will help someone who needs to just instantiate a collection from an array, or someone who needs to figure out how to add a default value for a collection in iReport.

If you enjoyed this post, make sure you subscribe to my RSS feed!

 

 

Disclosure: All of the products and services discussed on this site were purchased by myself, unless otherwise noted. Affiliate links are sometimes included in the posts. I generally don't get freebies to review or get paid to review things (outside of affiliate links). If I get it for free, I'll tell you. Material compensation does not influence my opinion and my views are my own.

 

Category: Programming

Tagged: , ,

Viewed:1

3 Responses

  1. anonim says:

    thanks!! very helpfull

  2. softboxkid says:

    i’ve got the problem. I have reports that produces an output based on parameter. Let say i’ve got 3 param. User didnt enter any value in 2nd param, but the 1st n 3rd param have value. How the report’s SQL statement will be looks like? is thare any solution for this kind of problem?

  3. Douglas Hammond says:

    This is handy too

    Arrays.asList(“1,2,3,4,5,6,7,8,9,10,11,12,23″.split(“,”))

Leave a Reply

Contact Information

Eric Holsinger
Saco, ME 04072
ph: 207 . 749 . 1703
eM: eric.holsinger@gmail.com
My company: Whirlidoo, LLC

View Eric Holsinger's profile on LinkedIn

Categories

My Twitter noise...

  • Sencha Touch had been slick, but oddball things, like setting scrollable to false on a form panel to render it, cause me stress. 17 hrs ago
  • Google Drive? 2 days ago
  • Am I the only one who thinks coffee from a French press tastes like coffee with little tiny coffee grounds all over my tongue? 3 days ago
  • More updates...

Posting tweet...

Powered by Twitter Tools


Banner