0

I'm trying to pass data that is available to the main report also to the subreport using the expression $P{REPORT_DATA_SOURCE}, but none of it is getting passed to subreport. I know since I have set the whenNoDataType="AllSectionsNoDetail"

The collection I'm reading in the field variables, I want to re-use the same collection in the subreport. I have gone through this link and tried all suggested approached to this but nothing works. How to pass main report data source to subreport (JasperReports)?

Below is my main report jrxml. It just prints the subreport parameter passed to the subreport, no detail section for subreport

<?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="statement" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="30" rightMargin="30" topMargin="20" bottomMargin="20" uuid="628d791a-f6fa-4391-9205-ea1764e19925">
    <property name="ireport.scriptlethandling" value="0"/>
    <property name="ireport.encoding" value="UTF-8"/>
    <import value="net.sf.jasperreports.engine.*"/>
    <import value="java.util.*"/>
    <import value="java.text.SimpleDateFormat"/>
    <import value="net.sf.jasperreports.engine.data.*"/>

    <field name="subpostingid" class="java.lang.String">
        <fieldDescription><![CDATA[subpostingid]]></fieldDescription>
    </field>
    <field name="tgtaccountnumber" class="java.lang.String">
        <fieldDescription><![CDATA[tgtaccountnumber]]></fieldDescription>
    </field>
    <field name="contraaccountname" class="java.lang.String">
        <fieldDescription><![CDATA[contraaccountname]]></fieldDescription>
    </field>
    <field name="debit" class="java.lang.String">
        <fieldDescription><![CDATA[debit]]></fieldDescription>
    </field>

    <title>
        <band height="367" splitType="Stretch">
            <textField isBlankWhenNull="false">
                <reportElement key="textField-9" x="0" y="10" width="324" height="30" uuid="6a6eb0ed-f5f4-4212-922e-527f7c8de372"/>
                <textFieldExpression><![CDATA[$R{fundsTransferApprovals}]]></textFieldExpression>
            </textField>            
        </band>
    </title>
    <columnHeader>
        <band height="53" splitType="Stretch">
            <textField isBlankWhenNull="false">
                <reportElement key="textField-15" x="0" y="0" width="324" height="27" uuid="ef3e213b-e902-4fd6-92ef-c072e7676648"/>
                <textFieldExpression><![CDATA[$R{beneficiaryDetails}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="false">
                <reportElement key="textField-15" x="0" y="30" width="80" height="15" uuid="ef3e213b-e902-4fd6-92ef-c072e7676648"/>
                <textFieldExpression><![CDATA[$R{id}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="false">
                <reportElement key="textField-16" x="80" y="30" width="200" height="15" uuid="5c1562ba-e316-4d69-bfb9-690aa65c8ccb"/>
                <textFieldExpression><![CDATA[$R{beneficiaryName}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="false">
                <reportElement key="textField-17" x="280" y="30" width="140" height="15" uuid="f60d6a74-7ff1-4a6c-b5c4-17108b774e7f"/>
                <textFieldExpression><![CDATA[$R{beneficiaryAccount}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="false">
                <reportElement key="textField-18" x="420" y="30" width="113" height="15" uuid="74f307a6-533a-4be8-a340-7d2d8b36b6aa"/>
                <textFieldExpression><![CDATA[$R{amount}]]></textFieldExpression>
            </textField>
        </band>
    </columnHeader>
    <detail>
        <band height="33" splitType="Stretch">
            <printWhenExpression><![CDATA[java.lang.Boolean.valueOf($F{subpostingid} != null)]]></printWhenExpression>
            <textField pattern="" isBlankWhenNull="false">
                <reportElement key="textField" x="0" y="0" width="80" height="16" isRemoveLineWhenBlank="true" forecolor="#000000" uuid="b0dbca80-0f46-4e85-8e0f-551d143cad60"/>
                <textFieldExpression><![CDATA[$F{subpostingid}]]></textFieldExpression>
            </textField>
            <textField pattern="" isBlankWhenNull="false">
                <reportElement key="textField" x="80" y="0" width="200" height="16" forecolor="#000000" uuid="d772ae5d-52dd-46b1-a60d-67b92a7153e1"/>
                <textFieldExpression><![CDATA[$F{contraaccountname}]]></textFieldExpression>
            </textField>
            <textField pattern="" isBlankWhenNull="false">
                <reportElement key="textField" x="280" y="0" width="140" height="16" forecolor="#000000" uuid="cc617ff8-0649-4b20-bbbd-a082c29a5410"/>
                <textFieldExpression><![CDATA[$F{tgtaccountnumber}]]></textFieldExpression>
            </textField>
            <textField pattern="" isBlankWhenNull="false">
                <reportElement key="textField" x="420" y="0" width="114" height="16" forecolor="#000000" uuid="bbf7210c-0979-49dc-b213-629b10e17f1d"/>
                <textFieldExpression><![CDATA[$F{debit}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <summary>
        <band height="130" splitType="Stretch">
            <subreport>
                <reportElement x="0" y="0" width="500" height="100" uuid="361dc76f-623e-4683-97df-252ccda05faa"/>
                <subreportParameter name="headingtext">
                    <subreportParameterExpression><![CDATA[$R{listOfSignatories}]]></subreportParameterExpression>
                </subreportParameter>               

                <dataSourceExpression><![CDATA[($P{REPORT_DATA_SOURCE})]]></dataSourceExpression>
                <subreportExpression><![CDATA["C:\\path\\approvals_subreport.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </summary>
</jasperReport>

My subreport:

<?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="approvals_subreport" pageWidth="500" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="500" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="89712d9b-194d-4499-875a-fe91d1a14964">
    <property name="ireport.scriptlethandling" value="0"/>
    <property name="ireport.encoding" value="UTF-8"/>
    <import value="net.sf.jasperreports.engine.*"/>
    <import value="java.util.*"/>
    <import value="java.text.SimpleDateFormat"/>
    <import value="net.sf.jasperreports.engine.data.*"/>
    <parameter name="headingtext" class="java.lang.String" isForPrompting="false"/>
    <parameter name="column1text" class="java.lang.String" isForPrompting="false"/>
    <parameter name="column2text" class="java.lang.String" isForPrompting="false"/>
    <parameter name="column3text" class="java.lang.String" isForPrompting="false"/>

    <field name="username" class="java.lang.String">
        <fieldDescription><![CDATA[username]]></fieldDescription>
    </field>
    <field name="loginid" class="java.lang.String">
        <fieldDescription><![CDATA[loginid]]></fieldDescription>
    </field>
    <field name="approvaltime" class="java.lang.String">
        <fieldDescription><![CDATA[approvaltime]]></fieldDescription>
    </field>
    <title>
        <band height="31" splitType="Stretch">
            <textField isBlankWhenNull="false">
                <reportElement key="textField-10" x="0" y="0" width="400" height="30" uuid="71c2ef41-1675-47cf-8f40-0eaec10d047b"/>
                <textFieldExpression><![CDATA[$P{headingtext}]]></textFieldExpression>
            </textField>
        </band>
    </title>
    <columnHeader>
        <band height="17" splitType="Stretch">
            <textField isBlankWhenNull="false">
                <reportElement key="textField-15" x="0" y="0" width="130" height="15" uuid="ef3e213b-e902-4fd6-92ef-c072e7676648"/>
                <textFieldExpression><![CDATA[$P{column1text}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="false">
                <reportElement key="textField-16" x="130" y="0" width="230" height="15" uuid="5c1562ba-e316-4d69-bfb9-690aa65c8ccb"/>
                <textFieldExpression><![CDATA[$P{column2text}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="false">
                <reportElement key="textField-17" x="360" y="0" width="140" height="15" uuid="f60d6a74-7ff1-4a6c-b5c4-17108b774e7f"/>
                <textFieldExpression><![CDATA[$P{column3text}]]></textFieldExpression>
            </textField>
        </band>
    </columnHeader>
    <detail>
        <band height="50">
            <staticText>
                <reportElement x="26" y="10" width="100" height="30" uuid="173d8ef0-4a69-4661-b320-6a1e282be380"/>
                <text><![CDATA[text here]]></text>
            </staticText>
        </band>
    </detail>
</jasperReport>

I have tried to declare my main report data source as

And use it in my subreport expression

And got error:

ERROR p: default-threadpool; w: Idle 20200313 13:37:35 [ReportManager] ReportManager.generateReport : Errors were encountered when compiling report expressions class file:
1. The constructor JRXmlDataSource(Collection) is undefined
                value = new net.sf.jasperreports.engine.data.JRXmlDataSource(((java.util.Collection)field_approvals.getValue())); //$JR_EXPR_ID=45$
Alex K
  • 22,315
  • 19
  • 108
  • 236
R. Sid
  • 9
  • 4
  • You need to specify the type of the data source that you pass to the main report. – Narcis Mar 13 '20 at 10:57
  • it's actually an xml data source, so what should be specified and where would that be? Also I read the concept of consumable, is that the problem here. that the data is already consumed and no more data records to be shared with subreport? – R. Sid Mar 13 '20 at 11:43
  • please check my updates in the post, added more details – R. Sid Mar 13 '20 at 13:40
  • Please disregard my comment/answer about `REPORT_DATA_SOURCE` parameter being `null`. I was actually thinking of the `REPORT_CONNECTION` parameter which is `null` for any non-JDBC based connections. Did you manage to sort your issue out? – Narcis Apr 09 '20 at 08:59

0 Answers0