简体   繁体   中英

Using a POJO as an iReport data source

I have a POJO that compiles data from various sources 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 POJOs populated with data from various sources (such as the billing and shipping addresses as Address objects).

Can I use this as a data source within iReport?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM