I need to populate a few subreports with lists of different objects. Basically lets say i have the following:
Subreport on used Vehicles
Subreport on new Vehicles<
i was the same problems with you and i solved it using the tag List of jasper, i used datasource in my class java, for example: parameter.put("MyList", new JRBeanCollectionDataSource(ListObjects)); in JRXML
In palete of Jasper, choose the tag LIST and drag and drop in your relatory after choose
now go to outline of jasper and - dataset properties - edit and query filter ... ... - javabean - search you class (I using eclipse, so it's easy to search my class) - add fields to use
Selecting your SubReport you can set the property "Connection type" as "Use a data source expression" and inside the property "Data Source Expression" you set this:
new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{yourFieldHere})
Where your "yourFieldHere" is a list (don't forget to set the "Field Class" inside your field properties as a java.util.List as well)
Ok, then you need create two fields with the Field Class as java.util.List, one for each list (newVehiclesList and usedVehiclesList).
Put your two SubReports wherever you want and click on each one doing the following steps:
Change the "Connection type" to "Use a datasource expression" then change the "Data Source Expression" to new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{yourField})
Done.
ps: In order to use the fields inside your newVehiclesList and usedVehiclesList you have to create them inside of their own subReports.