从子操作到主报表的返回值为null [英] Returned value from subeport to main report is null

查看:97
本文介绍了从子操作到主报表的返回值为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想简单地将子报表中的值返回到主报表,但在执行报表时始终显示 null 。使用iReport 5.1.0。

I want to simply return a value from sub report to main report, but always shows null when the report is executed. Using iReport 5.1.0.

<?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="report4" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ce028d85-f7e8-4abd-ad6b-e3b2ba04d14e">
<property name="ireport.zoom" value="1.0"/>
<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:\\Users\\DellXFR\\"]]></defaultValueExpression>
</parameter>
<variable name="z" class="java.lang.Integer" calculation="System">
    <variableExpression><![CDATA[8]]></variableExpression>
</variable>
<background>
    <band splitType="Stretch"/>
</background>
<title>
    <band height="79" splitType="Stretch"/>
</title>
<detail>
    <band height="125" splitType="Stretch">
        <subreport>
            <reportElement uuid="0c501730-d98a-4982-9953-2939f127ad9e" x="40" y="10" width="200" height="100"/>
            <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
            <returnValue subreportVariable="x" toVariable="z"/>
            <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "report4_subreport1.jasper"]]></subreportExpression>
        </subreport>
        <textField evaluationTime="Band">
            <reportElement uuid="9020a8d9-5799-4907-b8a3-704f41ffdcc0" x="399" y="73" width="100" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$V{z}]]></textFieldExpression>
        </textField>
    </band>
</detail>
<summary>
    <band height="42" splitType="Stretch"/>
</summary>
  </jasperReport>



子报告



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="report4_subreport1" language="groovy" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="78290b3a-34c2-496e-86ff-e213ca2c1039">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString language="SQL">
    <![CDATA[select * from ot;]]>
</queryString>
<field name="salscheme_id" class="java.lang.String">
    <fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="ot_amount" class="java.lang.Double">
    <fieldDescription><![CDATA[]]></fieldDescription>
</field>
<variable name="x" class="java.lang.Integer">
    <variableExpression><![CDATA[1]]></variableExpression>
</variable>
<group name="salscheme_id">
    <groupExpression><![CDATA[$F{salscheme_id}]]></groupExpression>
</group>
<background>
    <band splitType="Stretch"/>
</background>
<detail>
    <band height="125" splitType="Stretch"/>
</detail>
    </jasperReport>


推荐答案

将变量从子报表传递到主报表,如下所示: / p>

Pass variables from subreport to main report as follows:


  1. 在主报告中,创建一个变量:

  1. In the main report, create a variable:

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

注意:设置计算值。

在子报表中,还要创建一个变量:

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.

在主报表中,在子报表标记中设置子报表返回值:

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

<returnValue subreportVariable="returnValue" toVariable="subReportValue"/>


  • 如果你想把 subReportValue 在详细信息区域中,只需设置 textField evalutationTime ,因此需要在子报告之后(否则它仍为空)。

  • 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>
    


  • 如果它不在细节带集中 evaluationTime =报告用于分组。要了解不同的评估时间,请参阅 EvaluationTimeEnum

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

    完成后重新编译子报表,因为主报表引用了编译的 .jasper 文件,而不是 .jrxml source。

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

    这篇关于从子操作到主报表的返回值为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆