开发者

How do I iterate over a collection that is in an object passed as parameter in a jasper report?

开发者 https://www.devze.com 2022-12-28 18:01 出处:网络
I have an object A that has as an instance variable a collection of object Bs. Example: public class A{

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:

  1. the objectA as a concrete parameter and
  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消