How to show JRBeanCollectionDataSource data with help of Table component?

1.Send your datasource from the server as a parameter, and fill the report with a different one (can be empty).

JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(dataList);
        Map parameters = new HashMap();
        parameters.put("INFO", "Hello");
        parameters.put("DS1", beanColDataSource);

        JasperReport report = (JasperReport) JRLoader.loadObject("src/test/ireport/ShowPerson.jasper");
        JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, new JREmptyDataSource());

2.Decalre a new parameter in the report of type JRBeanCollectionDataSource

<parameter name="DS1" class="net.sf.jasperreports.engine.JRBeanCollectionDataSource"/>

3.Set TableDatasource to use the $P{DS1} parameter.

<jr:table ...>
    <datasetRun subDataset="Table Dataset 1">
        <datasetParameter name="REPORT_DATA_SOURCE">
             <datasetParameterExpression><![CDATA[$P{DS1}]]></datasetParameterExpression>
        </datasetParameter>
    </datasetRun>
.....

4.Declare the fields (name, age) in Table Dataset 1.

5.In the table, in the DetailBand add a TextField in each column with the corresponding field ($F{name} and $F{age} respectively).

Leave a Comment