Search code examples
jasper-reports

Jasper report iterate over array list


how can I create report that will iterate over arraylist in detail section that is passed as parameter in Jasper report?

Is that even possible? I searched and I found soloution that you have to add ArrayList as datasource. How do I do that?

Regards


Solution

  • You can create an SubReport an pass the ArrayList as DataSourceExpression:

            <subreport>
                ...
                <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{arrayList})]]></dataSourceExpression>
                <subreportExpression><![CDATA["subreport.jasper"]]></subreportExpression>
            </subreport>
    

    Javadoc:

    http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/data/JRBeanCollectionDataSource.html