JasperReport / SubReport not displayed

We are using the open source framework JasperReports to creating PDF reports.

One of my Team members wanted to create a MasterReport with a SubReport. The SubReport was nothing special, it included just static Text.The problem was, that the subreport was not rendered, it was always empty.

The problem was that the subreport need to have a data connection. Even you don’t need one. The solution is to include a empty DataSource like this:

<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>

The sub report definition in the master report looks like this:

<subreport>
 <reportElement x="0" y="246" width="504" height="100"/>
 <subreportParameter name="nameLabel"/>
 <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
 <subreportExpression><![CDATA[$P{SUBREPORT_DIR}]]></subreportExpression>
 </subreport>

Published by Robert Reiz

CEO @ VersionEye. Passionated software developer since 1998.

5 thoughts on “JasperReport / SubReport not displayed

  1. You can also do the following:

    – In the sub-report set the property `whenNoDataType=”NoDataSection”` on “.
    – Put your static elements in the “ band.

    This way you don’t have to set the `dataSourceExpression`.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: