如何解决另一个子报表中的子报表仅打印对象列表的第一项
我正在尝试使用带有子报表的主报表,而这个也带有子报表。 我有一个对象列表,我将其作为来自JAVA的参数传递。 当我打印Jaspers时,仅打印列表中的第一项,并且我不知道为什么(如果我仅将Master与ONE子报表一起使用,它将打印所有对象并正确显示所有数据)。
代码为: JAVA (最相关的部分)
Map<String,Object> parametrosTomaMuestra = new HashMap<>();
List<ObjectA> muestras = tomaMuestras.getMuestras();
List<JasperPrint> printList = new ArrayList<JasperPrint>();
parametrosTomaMuestra.put("subReportTomaMuestra",pathReport);
parametrosTomaMuestra.put("muestras",new JRBeanCollectionDataSource(muestras));
try {
JasperReport apdoTomaMuestras = (JasperReport) JRLoader.loadobjectFromFile(pathReport + "/apdoTomaMuestras.jasper");
printList.add(JasperFillManager.fillReport(apdoTomaMuestras,parametrosTomaMuestra,new JREmptyDataSource()));
} catch (JRException e) {
e.printstacktrace();
}
MASTER JRXML
<?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="apdoTomaMuestras" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="13a4a96f-ef00-4573-b951-f01c73cb0d60">
<parameter name="muestras" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<parameter name="subReportTomaMuestra" class="java.lang.String"/>
<queryString>
<![CDATA[]]>
</queryString>
<detail>
<band height="258" splitType="Stretch">
<subreport>
<reportElement x="20" y="30" width="505" height="228" uuid="eb89d398-4435-49ad-a886-9f1a3ad76e79"/>
<subreportParameter name="subReportTomaMuestra">
<subreportParameterExpression><![CDATA[$P{subReportTomaMuestra}]]></subreportParameterExpression>
</subreportParameter>
<dataSourceExpression><![CDATA[$P{muestras}]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{subReportTomaMuestra} + "tomaMuestra.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</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="tomaMuestra3" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="70bd6c22-e031-45e8-9ba6-d46b8f4bb20f">
<parameter name="subReportTomaMuestra" class="java.lang.String"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="codigo" class="java.lang.String"/>
<detail>
<band height="446" splitType="Stretch">
<staticText>
<reportElement x="3" y="130" width="68" height="20" uuid="e9d20cf5-abd3-4b2a-bd13-5bb2eee4957f"/>
<textElement>
<font fontName="Noto Sans HK Black" isBold="true"/>
</textElement>
<text><![CDATA[Origen:]]></text>
</staticText>
<textField>
<reportElement x="70" y="130" width="100" height="20" uuid="aa8869c6-af16-4376-930b-387a88c9bc62"/>
<textFieldExpression><![CDATA[$F{origen}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="110" y="100" width="100" height="16" uuid="1682066d-193c-4df6-b0fd-305ccd9676f2"/>
<textFieldExpression><![CDATA[$F{codigo}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="2" y="100" width="108" height="16" forecolor="#092382" uuid="519eb0f2-e970-4b94-925b-91d5f0aa21d4"/>
<textElement textAlignment="Left">
<font fontName="Noto Sans HK Black" size="11"/>
</textElement>
<text><![CDATA[Toma de muestra:]]></text>
</staticText>
<subreport>
<reportElement x="2" y="272" width="550" height="174" uuid="ccbbe4cf-52e6-4551-98b1-c3f397f21b65"/>
<subreportParameter name="subReportMuestraOrigenA">
<subreportParameterExpression><![CDATA[$P{subReportTomaMuestra}]]></subreportParameterExpression>
</subreportParameter>
<dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{subReportTomaMuestra} + "muestraOrigenA.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
SUB 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="muestraOrigenA" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" whenResourceMissingType="Error" uuid="aa7ff2e8-0339-46e8-afde-9b1d5f79c82d">
<parameter name="muestras" class="es.sigma.imina.modelo.tomamuestras.Muestra"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="afeccionesDescFoco" class="java.lang.String"/>
<field name="afeccionesOrigenAguasSup" class="java.lang.String"/>
<field name="afeccionesOrigen" class="java.lang.String"/>
<field name="ph" class="java.lang.Integer"/>
<field name="conductividadElectrica" class="java.lang.Float"/>
<detail>
<band height="446" splitType="Stretch">
<staticText>
<reportElement x="0" y="23" width="155" height="20" uuid="28affa9e-e432-4752-82bc-4839d90a914c"/>
<textElement>
<font fontName="Noto Sans HK Black" isBold="true"/>
</textElement>
<text><![CDATA[Origen de aguas superficiales:]]></text>
</staticText>
<staticText>
<reportElement x="280" y="23" width="44" height="20" uuid="5f8d6af0-fae0-4801-8f36-555da13637fb"/>
<textElement>
<font fontName="Noto Sans HK Black" isBold="true"/>
</textElement>
<text><![CDATA[Origen:]]></text>
</staticText>
<staticText>
<reportElement x="0" y="43" width="155" height="20" uuid="745ca6b1-c1f7-41bd-b1c8-d8eb1b9e7a66"/>
<textElement>
<font fontName="Noto Sans HK Black" isBold="true"/>
</textElement>
<text><![CDATA[Descripción del foco:]]></text>
</staticText>
<staticText>
<reportElement x="0" y="113" width="251" height="20" forecolor="#092382" uuid="ee62758c-d8be-464b-8b2f-23397b2611f3"/>
<textElement>
<font fontName="Noto Sans HK Black" size="11"/>
</textElement>
<text><![CDATA[En campo (mediante sondas)]]></text>
</staticText>
<staticText>
<reportElement x="280" y="173" width="130" height="20" uuid="b34814e6-17bb-4a44-921e-b896e5a4ec8a"/>
<textElement>
<font fontName="Noto Sans HK Black" isBold="true"/>
</textElement>
<text><![CDATA[Conductividad eléctrica:]]></text>
</staticText>
<staticText>
<reportElement x="0" y="143" width="251" height="20" forecolor="#092382" uuid="af2f22f5-2b31-46ef-92d6-82a1b53bef0d"/>
<textElement>
<font fontName="Noto Sans HK Black" size="11"/>
</textElement>
<text><![CDATA[En laboratorio]]></text>
</staticText>
<textField>
<reportElement x="27" y="173" width="103" height="18" uuid="068d1149-53e9-4490-8502-5d8a4f83ecb3"/>
<textFieldExpression><![CDATA[$F{ph}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="324" y="23" width="126" height="20" uuid="f812038f-0b6c-49c2-86be-0ebb72cf5197"/>
<textFieldExpression><![CDATA[$F{afeccionesOrigen}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="63" width="550" height="40" uuid="b9cc8d83-8ec1-40bf-9029-e17998768fad"/>
<textFieldExpression><![CDATA[$F{afeccionesDescFoco}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="410" y="173" width="100" height="20" uuid="4c30bbb1-9d66-4673-86ad-5765d8c6cc3c"/>
<textFieldExpression><![CDATA[$F{conductividadElectrica}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="155" y="23" width="125" height="20" uuid="b2a52619-5ac6-4884-b0fa-88f772cf68d3"/>
<textFieldExpression><![CDATA[$F{afeccionesOrigenAguasSup}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="173" width="25" height="20" uuid="db0290ba-f224-4a9e-8a3e-1c87e611324b"/>
<textElement>
<font fontName="Noto Sans HK Black" isBold="true"/>
</textElement>
<text><![CDATA[PH:]]></text>
</staticText>
</band>
</detail>
</jasperReport>
请不要理会jrxml的简单设计,我只是删除了不相关的信息,因为这样做太久了。 有想法吗?
解决方法
在您的“ SUBREPORT”中,这是不正确的:
<dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
由于从未设置$P{REPORT_DATA_SOURCE}
,因此“ SUB SUBREPORT”没有数据源。
我刚刚解决了将新的 net.sf.jasperreports.engine.JREmptyDataSource()数据从子报表扩展到子报表?的问题!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。