jasper-reports - 子报表变量始终返回 null
问题描述
我需要在主报告中放置一个变量,该变量的值来自子报告。我按照网上的说明进行操作,但我总是得到空值。为了测试,我将“18”放在子报表变量的表达式中,但返回null。
有人能帮我吗?我将把JRXML放在下面。
我在主报告中创建了一个变量 var1:
- 名称:var1
- 计算:系统
- 重置类型:报告
- 增量类型:无
在子报表中,我创建了变量 returnValue
- 计算:无计算功能
- 表达:18
- 增量类型:无
- 重置类型:报告
在master中,我配置了返回值:
- 从变量:returnValue
- 到变量:var1
- 计算类型:无
在两个xml文件之后
掌握
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 4.0.2 -->
<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="master" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<variable name="var1" class="java.lang.Integer" calculation="System"/>
<title>
<band height="79" splitType="Stretch">
<staticText>
<reportElement x="153" y="26" width="100" height="30"/>
<text><![CDATA[MASTER]]></text>
</staticText>
</band>
</title>
<summary>
<band height="246" splitType="Stretch">
<subreport>
<reportElement x="80" y="10" width="360" height="50"/>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<returnValue subreportVariable="returnValue" toVariable="var1"/>
<subreportExpression><![CDATA["sub1.jasper"]]></subreportExpression>
</subreport>
<textField>
<reportElement x="149" y="147" width="100" height="30"/>
<textFieldExpression><![CDATA[$V{var1}]]></textFieldExpression>
</textField>
</band>
</summary>
</jasperReport>
子报告
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 4.0.2 -->
<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="sub1" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<variable name="returnValue" class="java.lang.Integer">
<variableExpression><![CDATA[18]]></variableExpression>
</variable>
<title>
<band height="79" splitType="Stretch">
<staticText>
<reportElement x="212" y="24" width="100" height="30"/>
<text><![CDATA[SUB 1]]></text>
</staticText>
</band>
</title>
</jasperReport>
解决方案
- 一个问题是子报表永远不会被执行,因为它的主报表
dataset
不返回任何行。因此,When No Data Type
将子报告从更改<NULL>
为All Sections No Detail
-
- 其次
returnValue
,子报告中的变量Reset type
具有None
-
- 最后,
var1
使用渲染的变量TextField
应该Evaluation Time
具有Report
-
以下是更新的 JRXML -
掌握
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.15.0.final using JasperReports Library version 6.15.0-dd49bfb94918336b8321d5507193f0169ead4e95 -->
<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="master" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="d1a326d7-0db4-41f6-9791-6c0abc454731">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<variable name="var1" class="java.lang.Integer" calculation="System"/>
<title>
<band height="79" splitType="Stretch">
<staticText>
<reportElement x="153" y="26" width="100" height="30" uuid="ccc1c45e-e056-4a8e-8adc-cebefd388bc9"/>
<text><![CDATA[MASTER]]></text>
</staticText>
</band>
</title>
<summary>
<band height="246" splitType="Stretch">
<subreport>
<reportElement x="80" y="10" width="360" height="50" uuid="e251bfe7-5e81-4b79-9bc6-5f0e6c1d9555"/>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<returnValue subreportVariable="returnValue" toVariable="var1"/>
<subreportExpression><![CDATA["sub.jasper"]]></subreportExpression>
</subreport>
<textField evaluationTime="Report">
<reportElement x="149" y="147" width="100" height="30" uuid="24c3289e-f7a5-4137-9254-1fa2605f6741"/>
<textFieldExpression><![CDATA[$V{var1}]]></textFieldExpression>
</textField>
</band>
</summary>
</jasperReport>
子报告
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.15.0.final using JasperReports Library version 6.15.0-dd49bfb94918336b8321d5507193f0169ead4e95 -->
<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="sub1" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="97bfa906-b658-45f6-aff8-3bfa505251b3">
<variable name="returnValue" class="java.lang.Integer" resetType="None">
<variableExpression><![CDATA[18]]></variableExpression>
</variable>
<title>
<band height="79" splitType="Stretch">
<staticText>
<reportElement x="212" y="24" width="100" height="30" uuid="9332a235-2823-4b53-b6f8-0a7c56d58aee"/>
<text><![CDATA[SUB 1]]></text>
</staticText>
</band>
</title>
</jasperReport>
推荐阅读
- kotlin - 未解决的引用:使用 `it` 引用数字类型时的 MAX_VALUE
- javascript - JS:如何为页面滚动添加摩擦/动力?
- python - 如何使用模仿此 R 代码行为的 Python 将文件发布到服务器?
- databricks - Aws S3 到 Databricks 挂载不起作用
- python - 将分割图矢量化为 RGB 颜色
- python-3.x - 谷歌分析管理 API
- flutter - 如何导入颤振(不是飞镖)收藏库?
- react-native - 为什么 hitSlop 在这个嵌套的 TouchableOpacity 组件中不起作用?
- python - 向量和标量之间的元素乘法与两个矩阵
- python - 从父目录导入 .py 文件