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

Posted by spderosso on Stack Overflow See other posts from Stack Overflow or by spderosso
Published on 2010-04-26T14:33:14Z Indexed on 2010/04/26 15:03 UTC
Read the original article Hit count: 280

Filed under:
|

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!

© Stack Overflow or respective owner

Related posts about jasper-reports

Related posts about java