Search code examples
jasper-reportssubreport

Jasper subreport not showing


I am using Eclipse JasperReports Studio and have run into a problem I can't resolve. I have a pretty basic report with detail fields which return about 30 rows. I have a subreport I want to incorporated into the main report but when I add it nothing displays. I have tried adding it to the Column Footer, in the Page Footer with my Page x of x fields, and in the detail field. Which didn't work so well since it added a blank spot between every row retrieved. I have other reports with sub-reports in various bands and they all work fine. Here is the subreport code for the col footer:

    <columnFooter>
    <band height="110">
        <subreport>
            <reportElement isPrintRepeatedValues="false" x="0" y="10" width="555" height="100" uuid="34205e71-ec6b-422c-aa27-057678430999"/>
            <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
            <subreportExpression><![CDATA["The_Report.jasper"]]></subreportExpression>
        </subreport>
    </band>
</columnFooter>

Any obvious reasons why this won't show up? I don't get any errors and the main report runs fine. The subreport works fine on it's own and it is in the same directory as the main report. I compiled it there and the .jasper file is there as well.


Solution

  • Verify that the Subreport Expression is pointing to the correct/expected subreport. There are times (often due to copying and/or hand-editing existing JRXML files) where the Subreport Expression is still pointing to the subreport Jasper file of the original, Main report. I just ran into this case, myself.

    Make sure that

    <subreportExpression><![CDATA["The_Report.jasper"]]></subreportExpression>
    

    isn't supposed to be something like

    <subreportExpression><![CDATA["The_New_SubReport.jasper"]]></subreportExpression>
    

    or contain the Subreport directory like

    <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "The_New_SubReport.jasper"]]></subreportExpression>
    

    You should also verify that your subreport doesn't require data in order to display. If it does and your query doesn't return any data, you can do the following:

    SELECT FIELD_NAME
    FROM TABLE
    WHERE KEY = $P{KEY}
    
    UNION ALL
    
    SELECT NULL AS FIELD_NAME
    FROM DUAL WHERE (
      SELECT COUNT(*)
      FROM TABLE
      WHERE KEY = $P{KEY}
    ) = 0