我正在使用JasperReports使用两个单独的查询为 Web 应用程序生成图形和表格。我的主要JRXML生成图表,我在Detail区域中包含一个子报表来生成表格。但是,当它呈现时,子报表似乎被呈现了多次(确切地说是 12 次),这导致生成的报表是 12 页上的相同图表和表格(彼此完全相同)。这通过在线应用程序和iReport都发生。
我的主要JRXML、子报表JRXML和报表生成代码如下(由于 NDA 原因,一些细节已被删除)。
任何有关问题所在的见解或想法都会非常有帮助。
主要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="report" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<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["<<PATH_TO_SUBREPORT>>"]]></defaultValueExpression>
</parameter>
<parameter name="param" class="java.util.Collection" />
<queryString language="SQL">
<![CDATA[<<DATABASE_QUERY>>]]>
</queryString>
<field name="FIELD1" class="java.lang.Integer"/>
<field name="FIELD2" class="java.sql.Date"/>
<field name="FIELD3" class="java.math.BigDecimal"/>
<field name="FIELD4" class="java.math.BigDecimal"/>
<field name="FIELD5" class="java.math.BigDecimal"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="10" splitType="Stretch"/>
</title>
<pageHeader>
<band height="5" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="5" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="513" splitType="Stretch">
<lineChart>
<chart>
<reportElement positionType="Float" x="51" y="0" width="680" height="400"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<categoryDataset>
<categorySeries>
<seriesExpression><![CDATA["FIELD1"]]></seriesExpression>
<categoryExpression><![CDATA[$F{f1}]]></categoryExpression>
<valueExpression><![CDATA[$F{f2}]]></valueExpression>
</categorySeries>
<categorySeries>
<seriesExpression><![CDATA["FIELD2"]]></seriesExpression>
<categoryExpression><![CDATA[$F{f1}]]></categoryExpression>
<valueExpression><![CDATA[$F{f2}]]></valueExpression>
</categorySeries>
<categorySeries>
<seriesExpression><![CDATA["FIELD3"]]></seriesExpression>
<categoryExpression><![CDATA[$F{f1}]]></categoryExpression>
<valueExpression><![CDATA[$F{f2}]]></valueExpression>
</categorySeries>
</categoryDataset>
<linePlot>
<plot labelRotation="-90.0"/>
<categoryAxisFormat labelRotation="-90.0">
<axisFormat>
<tickLabelFont>
<font size="12"/>
</tickLabelFont>
</axisFormat>
</categoryAxisFormat>
<rangeAxisMinValueExpression><![CDATA[0]]></rangeAxisMinValueExpression>
<rangeAxisMaxValueExpression><![CDATA[101]]></rangeAxisMaxValueExpression>
</linePlot>
</lineChart>
<subreport>
<reportElement x="377" y="413" width="425" height="100"/>
<subreportParameter name="param">
<subreportParameterExpression><![CDATA[$P{param}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "testReport.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
<columnFooter>
<band height="5" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="15" splitType="Stretch">
<textField>
<reportElement mode="Opaque" x="3" y="2" width="759" height="13" backcolor="#E6E6E6"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement mode="Opaque" x="762" y="2" width="40" height="13" backcolor="#E6E6E6"/>
<textElement/>
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement x="3" y="0" width="100" height="13"/>
<textElement/>
<textFieldExpression><![CDATA[new SimpleDateFormat("MM-dd-yyyy").format(
new java.util.Date())]]></textFieldExpression>
</textField>
</band>
</pageFooter>
<summary>
<band height="10" splitType="Stretch"/>
</summary>
</jasperReport>
子报告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="evcas_sub" language="groovy" pageWidth="450" pageHeight="150" columnWidth="10" leftMargin="10" rightMargin="10" topMargin="10" bottomMargin="10">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<style name="table">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table_TH" mode="Opaque" backcolor="#0000FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table_CH" mode="Opaque" backcolor="#BFBFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
<conditionalStyle>
<conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
<style backcolor="#EFEFFF"/>
</conditionalStyle>
</style>
<style name="Crosstab Data Text" hAlign="Center"/>
<parameter name="param" class="java.util.Collection" />
<queryString>
<![CDATA[<<DATABASE_QUERY>>]]>
</queryString>
<field name="FIELD1" class="java.lang.String"/>
<field name="FIELD2" class="java.math.BigDecimal"/>
<field name="FIELD3" class="java.math.BigDecimal"/>
<field name="FIELD4" class="java.math.BigDecimal"/>
<field name="FIELD5" class="java.math.BigDecimal"/>
<field name="FIELD6" class="java.math.BigDecimal"/>
<field name="FIELD7" class="java.math.BigDecimal"/>
<field name="FIELD8" class="java.math.BigDecimal"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="5" splitType="Stretch"/>
</title>
<pageHeader>
<band height="5"/>
</pageHeader>
<columnHeader>
<band height="12">
<textField>
<reportElement style="table_TH" x="0" y="0" width="50" height="12" backcolor="#FFFFFF"/>
<textElement>
<font size="9"/>
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA["FIELD1"]]></textFieldExpression>
</textField>
<textField>
<reportElement style="table_TH" x="50" y="0" width="50" height="12" backcolor="#FFFFFF"/>
<textElement>
<font size="9"/>
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA["FIELD2"]]></textFieldExpression>
</textField>
<textField>
<reportElement style="table_TH" x="100" y="0" width="50" height="12" backcolor="#FFFFFF"/>
<textElement>
<font size="9"/>
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA["FIELD3"]]></textFieldExpression>
</textField>
<textField>
<reportElement style="table_TH" x="150" y="0" width="50" height="12" backcolor="#FFFFFF"/>
<textElement>
<font size="9"/>
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA["FIELD4"]]></textFieldExpression>
</textField>
<textField>
<reportElement style="table_TH" x="200" y="0" width="50" height="12" backcolor="#FFFFFF"/>
<textElement>
<font size="9"/>
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA["FIELD5"]]></textFieldExpression>
</textField>
<textField>
<reportElement style="table_TH" x="250" y="0" width="50" height="12" backcolor="#FFFFFF"/>
<textElement>
<font size="9"/>
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA["FIELD6"]]></textFieldExpression>
</textField>
<textField>
<reportElement style="table_TH" x="300" y="0" width="50" height="12" backcolor="#FFFFFF"/>
<textElement>
<font size="9"/>
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA["FIELD7"]]></textFieldExpression>
</textField>
<textField>
<reportElement style="table_TH" x="350" y="0" width="50" height="12" backcolor="#FFFFFF"/>
<textElement>
<font size="9"/>
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA["FIELD8"]]></textFieldExpression>
</textField>
</band>
</columnHeader>
<detail>
<band height="12">
<textField>
<reportElement style="table_CH" x="0" y="0" width="50" height="12" backcolor="#FFFFFF"/>
<textElement>
<font size="8"/>
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA[$F{f1}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="table_CH" x="50" y="0" width="50" height="12" backcolor="#FFFFFF"/>
<textElement>
<font size="8"/>
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA[$F{f2}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="table_CH" x="100" y="0" width="50" height="12" backcolor="#FFFFFF"/>
<textElement>
<font size="8"/>
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA[$F{f3}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="table_CH" x="150" y="0" width="50" height="12" backcolor="#FFFFFF"/>
<textElement>
<font size="8"/>
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA[$F{f4}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="table_CH" x="200" y="0" width="50" height="12" backcolor="#FFFFFF"/>
<textElement>
<font size="8"/>
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA[$F{f5}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="table_CH" x="250" y="0" width="50" height="12" backcolor="#FFFFFF"/>
<textElement>
<font size="8"/>
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA[$F{f6}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="table_CH" x="300" y="0" width="50" height="12" backcolor="#FFFFFF"/>
<textElement>
<font size="8"/>
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA[$F{f7}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="table_CH" x="350" y="0" width="50" height="12" backcolor="#FFFFFF"/>
<textElement>
<font size="8"/>
<paragraph leftIndent="2"/>
</textElement>
<textFieldExpression><![CDATA[$F{f8}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="5" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="5" splitType="Stretch"/>
</pageFooter>
</jasperReport>
渲染代码:
String strFileName = "<<FILENAME>>";
File jrxml = new File(strFileName);
InputStream iStream = new FileInputStream(jrxml);
JasperReport objJReport = JasperCompileManager.compileReport(iStream);
JasperPrint objJPrint = JasperFillManager.fillReport(objJReport, hashMap, datasource.getConnection());
JasperExportManager.exportReportToPdfStream(objJPrint, os);