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 wan开发者_StackOverflow中文版t an instance of A to be the only source of information the jasper report gets. 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 sources of information:
- the objectA as a concrete parameter and
- the collection of object Bs that is in A as a bean data source
I want to pass one source of information only: objectA; and leave the data source as a JREmptyDataSource(). Is it possible to iterate over myList in the report? Even if there is an empty data source?
More generally speaking: How do I iterate over the Bs in A by passing only A?
Thanks!
Maybe it would be more appropriate to implement your own JRDataSource - one that iterates over the Bs.
精彩评论