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).
@laura: I get new error when trying set the TableDatasource to use the $P{DS1} parameter. net.sf.jasperreports.engine.JRBeanCollectionDataSource cannot be resolved to a type
Now, I have found the solution, maybe not the best.
Map parameters = new HashMap();
parameters.put("INFO", "Hello");
parameters.put("DS1", dataList);
JasperReport report = (JasperReport) JRLoader.loadObject("src/test/ireport/ShowPerson.jasper");
JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, new JREmptyDataSource());
Modify the class of $P{DS1} to java.util.Collection or java.util.List
And set the table datasource to
new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{DS1})