views:

415

answers:

1

I have a pojo that compiles data from various source into a single object. The object is instantiated with a single parameter. Example:

Invoice inv=new Invoice(1239);

This will bring back a complete invoice containing other POJO's populated with data from various sources (such as the billing/shipping address as Address objects).

My question is, can I use this a data source within iReport?

Thanks,

David

A: 

You could try use a JRMapCollectionDataSource from which you can build a DataSource from a collection.

You could take the values from the POJO object and place them into a collection if possible.

Here is some sample code for constructing a DataSource.

Collection<Map<String, Object>> myColl = new ArrayList<Map<String,Object>>();

Map<String, Object> map1 = new HashMap<String, Object>();
map1.put("Field1","Value1");
map1.put("Field2","Value2");
map1.put("Field3", someObject);
myColl.add(map1);

JRMapCollectionDataSource source = new JRMapCollectionDataSource(myColl);

Another option would be to create a custom datasource by implementing JRRewindableDataSource or JRDataSource.

Gordon