Search code examples
jasper-reportsjavabeans

Crosstab Data is empty when using a Java Bean Data Source?


I have a problem in jasper reports using Java Bean Data Source using Data Source Expression in crosstab as $P{REPORT_CONNECTION}

I can successfully populate data in detail section,

but when I try to use the bean data in crosstab; the crosstab is empty on preview.

Anyone who knows what to do on this particular setup?

enter image description here

enter image description here

enter image description here


Solution

  • $P{REPORT_CONNECTION} is the JDBC database connection, since you are using a "Java Bean Datasource", you should not pass the database connection but instead a JRDatasource.

    Passing a datasource to a crosstab is done by specifying the dataSourceExpression

    <crosstabDataset>
        <dataset>
            <datasetRun subDataset="Dataset1" uuid="bcc868c0-ea35-4a17-b570-2d51dbe93e8d">
                <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
            </datasetRun>
        </dataset>
    </crosstabDataset>
    

    However,

    If you like to use the current main report datasource (as above) you can simply not specify any dataset nor a connection, this will automatically use main datasource and there is no need to define a subDataset.

    but,

    You need to be careful, the JRDatasource is "consumed" when the it fills, hence if you have already used it once (detail band present in jrxml), it is consumed. To understand this better see for example How to use same JRBeanCollectionDataSource on multiple sub reports?