1
votes

I want to pass the datasource from main report to a subreport.

So I simply change Connection Type in iReport to Use a datasource expression and pass the REPORT_DATA_SOURCE parameter.

The report should generate a few hundred sites. And it computes 1 subreport per page.

The subreport only needs some lines of the datasource, so it uses his own WHERE in the query.

The problem is:

after changing the Connection Type from Connection to Data Source, the Report only displays the first site. It seems as if the subreport changes the dataset of the mainreport with its WHERE statement to only one line.

I have seen solutions for that http://www.billmann.de/2011/12/01/jasperreports-subreport-datasource/ but when I try this, I get an error:

java.lang.ClassCastException: net.sf.jasperreports.engine.JRResultSetDataSource cannot be cast to net.sf.jasperreports.engine.data.JRBeanCollectionDataSource

Are there other possibilities to clone a datasource? Or can I set something in Subreport, so that the datasource is not changed?

If I use Connection instead of DataSource, the Report works, but it renders 5 minutes and more, because every Subreport call generates its own Dataset.

1

1 Answers

2
votes

I am the author of the above blog entry and the type cast to JRBeanCollectionDataSource is necessary as the datasource we use is a JRBeanCollectionDataSource and this JRDatasSurce supports the cloneDataSource() method.

Not all JRDataSources support such a method. If you have the chance to read in the database programmatically and fill the data in another JRDataSource like JRMapArrayDataSource you can use the cloneDataSource() method.

I am not sure if this solution works with the additional where clause.