How do I iterate over a collection that is in an object passed as parameter in a jasper report?
- by spderosso
Hi,
I have an object A that has as an instance variable a collection of object Bs. Example:
public class A{
String name;
List<B> myList;
...
public List<B> getMyList(){
return myList;
}
...
}
I want this object to be the only source of information the jasper report gets, since all the information the report need is in A. I am currently doing something like:
A myObjectA = new A(...);
InputStream reportFile = MyPage.this.getClass().getResourceAsStream("test.jrxml");
HashMap<String, Object> parameters = new HashMap<String, Object>();
parameters.put("objectA", myObjectA);
...
JasperReport report = JasperCompileManager.compileReport(reportFile);
JasperPrint print = JasperFillManager.fillReport(report, parameters, new JRBeanCollectionDataSource(myObjectA.getMyList()));
return JasperExportManager.exportReportToPdf(print);
thereby passing "two" parameters, the objectA as a concrete parameter and the collection of object Bs that is in A as a bean data source. How do I iterate over the Bs in A by passing only A?
Thanks!