Search code examples
jasper-reports

Fix Subreport Expression Class in iReport


Lately I had a problem with printing a master-detail report using JavaBeans datasource (I didn't use MySQL datasource for some reasons).

I can not change the expression class of subreport to java.util.List (I had made the subreport.jrxml and mainreport.jrxml). But as you see in the picture below, that class expression is not exist in my subreport properties.

java.util.List not found here

Then I tried to write it manually. I added these codes to my XML file.

<subreport>
    <reportElement x="0" y="20" width="555" height="100"/>
    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{orderDetails})]]></dataSourceExpression>
    <subreportExpression class="java.util.List"><![CDATA[$P{SUBREPORT_DIR} + "sub_main_report.jasper"]]></subreportExpression>
</subreport>

Now it's showing another error like this. another error

Sorry if I've explained it bad. Have anyone here got the same problem with me?

Note: My iReport version is 4.0.1 with JDK 1.7 running in Linux Ubuntu 14.04 64-bit environment.


Solution

  • ThesubreportExpression can only be used with a few classes, such as java.lang.String. It cannot be java.util.List. Your second error message shows the list of accepted classes.

    Update

    You have to understand that the subreportExpression tells the system how to load the sub-report. There can only be one value. So the expression cannot be an java.util.List. If you have multiple sub-reports, you have to have multiple elements of subreport, each with its own subreportExpression.