iReport Designer 5.6.0 - subreport not displayed in the main report

0

I am trying to create the subreport in the main report only with the static texts.

Main report:

xml:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report1" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="f175bd48-f661-425f-a3e1-763996d44ca7">
    <property name="ireport.zoom" value="1.3310000000000004"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
        <defaultValueExpression><![CDATA["C:\\eclipse_workplace\\esd01\\src\\app\\app-gendoc\\gendoc-impl\\src\\main\\resources\\templates\\jasper\\"]]></defaultValueExpression>
    </parameter>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="0" width="100" height="20" uuid="a0319d8a-68cd-447a-8889-301e0d0139e3"/>
                <text><![CDATA[Hello Title]]></text>
            </staticText>
        </band>
    </title>
    <detail>
        <band height="125" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="0" width="100" height="20" uuid="471d80ae-9da4-4944-911a-f90acb8e0e91"/>
                <text><![CDATA[Hello Detail]]></text>
            </staticText>
            <subreport>
                <reportElement x="114" y="20" width="641" height="79" uuid="beace73f-401b-4406-a8b4-603a3df43a9e"/>
                <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "report1_subreport1.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </detail>
    <pageFooter>
        <band height="54" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="0" width="100" height="20" uuid="513068b2-28cf-4d3e-a2f5-fd57d9cdcc3b"/>
                <text><![CDATA[Hello Footer]]></text>
            </staticText>
        </band>
    </pageFooter>
</jasperReport>

Subreport:

xml:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report1_subreport1" language="groovy" pageWidth="802" pageHeight="555" orientation="Landscape" columnWidth="802" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="57901f58-6d39-40b8-9972-7f2dfff24f53">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <detail>
        <band height="125" splitType="Stretch">
            <staticText>
                <reportElement x="325" y="45" width="143" height="35" uuid="6977bf0b-7047-495c-b1e1-af3010a8cd39"/>
                <textElement>
                    <font size="24"/>
                </textElement>
                <text>
                    <![CDATA[Hello World]]>
                </text>
            </staticText>
        </band>
    </detail>
</jasperReport>

Now, when I am trying click to preview button from the main report, the subreport is not displayed. What am I doing wrong?

Preview from main report:

rusindes's picture
Joined: Sep 10 2019 - 7:18am
Last seen: 1 month 4 days ago

1 Answer:

1

As you don't pass any data nor use a query that returns any results inside your subReport this SubReport doesn't iterate through any records. So no detail is rendered at all.

So I would advice to use the "NoDataSection" in your SubReport for your static text sample and set the ReportProperty "WhenNoDataType" to "No Data Section" in the subreports jrxml.

Otherwise you could also pass an JREmptyDataSource as SubReport-DataSourceExpression instead the ReportConnection, so that the SubReport will render some dummy contents as well.

Or you place the static text just into the Title band of your SubReport and use "WhenNoDataType" = "AllSectionsNoDetail" to see whether your SubReport is called at all.

Or last but not least -  just create a query within the SubReport that will return some records. 

;-)

hth + regards

C-Box

C-Box's picture
2122
Joined: Jul 19 2006 - 5:58pm
Last seen: 18 hours 56 min ago
Feedback