Jasper report iterate over array list

Sobis picture Sobis · Nov 2, 2011 · Viewed 18.1k times · Source

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

Answer

itshorty picture itshorty · Nov 10, 2011

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