How to get report_count from a subreport in iReport

I have a summary report in my main report.

I need to hide the text if the sub report does not return a row.

I tried to get the number of sub-report entries by adding a new variable to the main report and setting it as the target variable in the return valuesproperty subreport(for rount_count), but when I run the main report, the value of the variable is null

+3
source share
1 answer

To count a subreport record

  • Define a variable in the main report

    <variable name="subReportCount" class="java.lang.Integer"/>
    
  • When calling subreport, set the return parameter to a variable

    <subreport>
        <reportElement x="100" y="20" width="400" height="20" uuid="a7a89ebb-54d4-4b6e-8c9f-c107e8a40bbb"/>
        <dataSourceExpression><![CDATA[... your datasource ...]]></dataSourceExpression>
        <returnValue subreportVariable="REPORT_COUNT" toVariable="subReportCount"/>
        <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "Your_subreport.jasper"]]></subreportExpression>
    </subreport>
    

textField, , textField ( , ).

textField evaluationTime

<textField evaluationTime="Report" pattern="###0">
    <reportElement positionType="Float" x="300" y="60" width="200" height="20" uuid="125aa2d0-3d4e-4377-bed1-b4531c9142c9"/>
    <textElement textAlignment="Right" verticalAlignment="Middle"/>
    <textFieldExpression><![CDATA[$V{subReportCount}]]></textFieldExpression>
</textField>

:

, , , , .
.
, , .
, , .
, .
, , , .
, , .
, , .

subreport

  • evalutationTime="Band"
  • evalutationTime="Report"
+6

Source: https://habr.com/ru/post/1623461/


All Articles