How to pass ArrayList to JasperReports?

后端 未结 3 2135
臣服心动
臣服心动 2020-12-18 05:23

I\'m new to JasperReports. I want to pass ArrayList to subreport of subreport.

I have master report which contains one subreport1 and this

相关标签:
3条回答
  • 2020-12-18 05:32

    It's done by passing a collection data-source: new BeanCollectionDataSource(yourArrayList);

    And then to obtain the JasperPrint object:

    JasperPrint jasperPrint = 
          JasperFillManager.fillReport(jasperReport, params, dataSource);
    

    To pass to a subreport, you have two options:

    • If it is a subreport-per-row, simply have the array as a property of the bean. I.e. List<Something> where Something has a property of type List<AnotherThing>
    • If it is one for the whole report, pass it as a parameter (params above).
    0 讨论(0)
  • 2020-12-18 05:33

    Step:1 define a field like
    field name="listCusipData" and class="java.util.ArrayList"

    Step:2 use this expression inside your sub report dataSourceExpression
    new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{listCusipData},false)

    0 讨论(0)
  • 2020-12-18 05:48

    You can do it using lists and/or subreports, datasources and JRBeanCollectionDatasource.

    Check this example:

    http://siempredesdeelcurro.blogspot.com.es/2013/06/jasper-reports-crear-report-utilizando.html

    It's in Spanish, but by your name I guess you will be able to read it ;)

    For non Spanish speakers you still can use it as at the end of the tutorial you can find the XML with the jrxml templates.

    0 讨论(0)
提交回复
热议问题