Returned value from subeport to main report is null

烂漫一生 提交于 2019-11-28 14:15:40
Petter Friberg

Pass variables from subreport to main report as follows:

  1. In the main report, create a variable:

    <variable name="subReportValue" class="java.lang.Integer"/>
    

    Note: Do not set calculation value.

  2. In the subreport, also create a variable:

    <variable name="returnValue" class="java.lang.Integer" calculation="First">
      <variableExpression><![CDATA[$F{myField}]]></variableExpression>
    </variable>
    

    Set the calculation and what you like to return. Note: Respect the class value of the main report variable, they need to be same class.

  3. In the main report, set the subreport return value in the subreport tag:

    <returnValue subreportVariable="returnValue" toVariable="subReportValue"/>
    
  4. If you like to put the subReportValue in the detail band, just must set the evalutationTime of the textField, hence it needs to be after subreport (otherwise its still null).

    <textField evaluationTime="Band">
            <reportElement x="251" y="109" width="100" height="20"/>
            <textElement lineSpacing="Single"/>
            <textFieldExpression class="java.lang.Integer"><![CDATA[$V{subReportValue}]]></textFieldExpression>
    </textField>
    

If it is not in the detail band set evaluationTime="Report" for grouping. To understand the different evaluationTime see EvaluationTimeEnum

Re-compile the subreport when finished, since the main report references the compiled .jasper file, not the .jrxml source.

set evaluation time of element to "band"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!