Jasper服务器子报告详细带

时间:2011-11-20 15:47:21

标签: jasper-reports jasperserver

我需要在详细信息带中创建子报告,我将主报告的相同数据源传递给子报告。 我面临的问题是,当它进入子报告时,它会递增索引计数器,这不允许添加剩余的子报告。

MainReport.jrxml

<group name="Account Summary">
    <groupHeader>
        <band height="100" splitType="Stretch">
            <printWhenExpression><![CDATA[$F{accountSummary.hasRepots}]]></printWhenExpression>
            <subreport isUsingCache="false">
                <reportElement x="28" y="0" width="540" height="100" isRemoveLineWhenBlank="true"/>
                <subreportParameter name="accountSummary">
                    <subreportParameterExpression><![CDATA[$F{accountSummary.hasRepots}]]></subreportParameterExpression>
                </subreportParameter>
                <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
                <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "SubReport.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </groupHeader>
</group>

SubReport.jrxml

<detail>
    <band height="100" splitType="Stretch">
        <subreport isUsingCache="false">
            <reportElement positionType="Float" x="0" y="0" width="540" height="100" isRemoveLineWhenBlank="true"/>
            <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
            <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + $F{subreportFileName}]]></subreportExpression>
        </subreport>
    </band>
</detail>

我从我的数据源传递$ F {subreportFileName}例如“SubSubReport.jrxml”,但它只显示第一个报告,我想由于我的索引计数器在我的子报告中耗尽所以我的子报告详细信息带不适合每个元素。

SubSubReport.jrxml

<field name="chartData.label" class="java.lang.String"/>
<field name="chartData.value" class="java.lang.Float"/>
<field name="value1" class="java.lang.String"/>
<field name="value2" class="java.lang.String"/>
<field name="value3" class="java.lang.String"/>
<pageHeader>
    <band height="114" splitType="Stretch">
        <staticText>
            <reportElement style="lbl-light-golden" x="12" y="19" width="170" height="67"/>
            <textElement>
                <font size="26"/>
            </textElement>
            <text><![CDATA[Some Label]]></text>
        </staticText>
        <pieChart>
            <chart evaluationTime="Band">
                <reportElement x="272" y="0" width="268" height="114"/>
                <chartTitle/>
                <chartSubtitle/>
                <chartLegend position="Left"/>
            </chart>
            <pieDataset>
                <keyExpression><![CDATA[$F{chartData.label}]]></keyExpression>
                <valueExpression><![CDATA[$F{chartData.value}]]></valueExpression>
                <labelExpression><![CDATA[null]]></labelExpression>
            </pieDataset>
            <piePlot isShowLabels="false" isCircular="true">
                <plot/>
                <itemLabel/>
            </piePlot>
        </pieChart>
    </band>
</pageHeader>
<columnHeader>
    <band height="18" splitType="Stretch">
        <line>
            <reportElement x="0" y="1" width="540" height="1"/>
        </line>
        <staticText>
            <reportElement style="lbl-black-table-header" x="12" y="4" width="158" height="14"/>
            <textElement/>
            <text><![CDATA[Header 1]]></text>
        </staticText>
        <staticText>
            <reportElement style="lbl-black-table-header" x="205" y="4" width="199" height="14"/>
            <textElement textAlignment="Right"/>
            <text><![CDATA[Header 2]]></text>
        </staticText>
        <staticText>
            <reportElement style="lbl-black-table-header" x="445" y="4" width="74" height="13"/>
            <textElement textAlignment="Center"/>
            <text><![CDATA[Header 3]]></text>
        </staticText>
        <line>
            <reportElement x="0" y="17" width="540" height="1"/>
        </line>
    </band>
</columnHeader>
<detail>
    <band height="18" splitType="Stretch">
        <textField isStretchWithOverflow="true">
            <reportElement positionType="Float" x="12" y="1" width="158" height="16"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{value1}]]></textFieldExpression>
        </textField>
        <textField isStretchWithOverflow="true">
            <reportElement positionType="Float" x="205" y="1" width="199" height="16"/>
            <textElement textAlignment="Right">
                <font isStrikeThrough="false"/>
            </textElement>
            <textFieldExpression><![CDATA[$F{value2}]]></textFieldExpression>
        </textField>
        <textField isStretchWithOverflow="true">
            <reportElement positionType="Float" x="445" y="1" width="74" height="16"/>
            <textElement textAlignment="Right"/>
            <textFieldExpression><![CDATA[$F{value3}]]></textFieldExpression>
        </textField>
    </band>
</detail>

我还尝试在“SubReport.jrxml”

中使用Groups而不是detail band

SubReport.jrxml

<group name="Sub report 1">
    <groupHeader>
        <band height="100" splitType="Stretch">
            <subreport isUsingCache="false">
                <reportElement positionType="Float" x="0" y="0" width="540" height="100" isRemoveLineWhenBlank="true"/>
                <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
                <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "SubSubReport.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </groupHeader>
</group>
<group name="Sub report 2">
    <groupHeader>
        <band height="200" splitType="Stretch">
            <staticText>
                <reportElement x="110" y="10" width="100" height="20"/>
                <textElement/>
                <text><![CDATA[Sub report 2]]></text>
            </staticText>
            <subreport isUsingCache="false">
                <reportElement positionType="Float" x="0" y="40" width="540" height="100" isRemoveLineWhenBlank="true"/>
                <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
                <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "SubSubReport1.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </groupHeader>
</group>

打印“Sub report 2”标签,但打印“SubSubReport1.jasper”没有成功

我做错了什么建议或任何有用的方向。

1 个答案:

答案 0 :(得分:0)

永远不应使用报表数据源来提供子报表。 REPORT_DATA_SOURCE是一个可消耗对象的数据源。

这意味着只能提供一次报告。因此,当主报表的每个记录都有自己的子报表时,参数技术不适用(除非主报表中只有一条记录)。我想这可能是你只看到一个的原因。