views:

243

answers:

1

Hello, I'm using JasperReports with JavaBeans (I need to print reports in a application that uses Hibernate). Now I can work out Beans collections and use them in JasperReports, but sometimes I wonder if there is a way to access bean properties without it being a collection. What I mean is that I use JRBeanCollectionSource as a source for the various subReports. Suppose I've a list of People and each of them has a Car property. Now is there a way to access directly car properties without seeing it as a collection?

A: 

You could try pulling the property out of the Bean and putting in a different DataSource like for example JRMapCollectionDataSource.

This would mean not having to deal with the whole Bean collection each time.

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);
Gordon
Thanks, the docs are not very clear about this...
gotch4
It's vague at the best of times...
Gordon