Мне нужно поместить в главный отчет переменную, значение которой взято из подотчета. Я следовал инструкциям из Интернета, но всегда получал ноль. Для тестирования я ввел 18 в выражение переменной подотчета, но вернул ноль.
Кто-нибудь может мне помочь? Я помещу JRXML ниже.
Я создал переменную var1 в главном отчете:
- Имя: var1
- Расчет: Система
- Тип сброса: Отчет
- Тип приращения: Нет
В подотчете я создал переменную returnValue
- Расчет: без функции расчета
- Выражение: 18
- Тип приращения: Нет
- Тип сброса: Отчет
В мастере настроил возвращаемое значение:
- Из переменной: 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>