How to get a return from a subreport in Jasper

Asked

Viewed 156 times

-1

Hello, I have a variable inside a subreport and I want to pass it to the mainreport, but for some reason the variable is arriving with null in the main report. I created an exmeplo variable To in the two reports to illustrate.


Variable declaration in subreport

...
    <variable name="A" class="java.lang.String" resetType="None">
        <variableExpression><![CDATA["teste"]]></variableExpression>
    </variable>
...

Variable declaration in mainreport

...
    <variable name="A" class="java.lang.String" resetType="None">
        <variableExpression><![CDATA[]]></variableExpression>
    </variable>
...

Call on the mainreport

...
            <subreport runToBottom="false">
                <reportElement uuid="5e524426-f04b-47d8-b7cd-2be45f031ebd" stretchType="RelativeToTallestObject" isPrintRepeatedValues="false" x="0" y="4" width="391" height="10" isPrintWhenDetailOverflows="true"/>
                <returnValue subreportVariable="A" toVariable="A"/>
                <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "subreport.jasper"]]></subreportExpression>
            </subreport>
...

Thanks in advance.

1 answer

0

It would be valid to pass which version you are using.

I think we are missing you define which type of return subreport expression is java.lang.String

Try:

    <subreport runToBottom="false">
        <reportElement uuid="5e524426-f04b-47d8-b7cd-2be45f031ebd" stretchType="RelativeToTallestObject" isPrintRepeatedValues="false" x="0" y="4" width="391" height="10" isPrintWhenDetailOverflows="true"/>
        <returnValue subreportVariable="A" toVariable="A"/>
        <subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "subreport.jasper"]]></subreportExpression>
    </subreport>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.