在ireport中显示独立于主数据源(主报表)的子报表

时间:2014-04-29 01:30:21

标签: jasper-reports

好吧,我有一个Master和一个子报告,在主报告中我有2个细节带。在第一个细节带中我放了“主数据源”(来自fillReport),详细的带2我把子报告(来自param的数据源)。

我的主报告配置为显示“所有部分,没有详细信息”,但问题是当“主数据源”没有记录时,子报告未显示。我需要显示子报表详细信息,而不依赖于“主数据源”的内容。

我该怎么做?

这是我的报告XML:

<?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="rf002" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="575" leftMargin="10" rightMargin="10" topMargin="10" bottomMargin="10" uuid="4436a245-e7f4-426f-aabc-806179a89e8a">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="84"/>
    <parameter name="pathSubreport" class="java.lang.String">
        <defaultValueExpression><![CDATA["/home/ronaldo/workspace/sender/src/main/webapp/WEB-INF/report/"]]></defaultValueExpression>
    </parameter>
    <parameter name="titulo" class="java.lang.String"/>
    <parameter name="endereco" class="java.lang.String"/>
    <parameter name="cep" class="java.lang.String"/>
    <parameter name="estado" class="java.lang.String"/>
    <parameter name="cidade" class="java.lang.String"/>
    <parameter name="razaoSocial" class="java.lang.String"/>
    <parameter name="pathLogomarca" class="java.lang.String"/>
    <parameter name="usuario" class="java.lang.String"/>
    <parameter name="dataFechamento" class="java.util.Date"/>
    <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
        <defaultValueExpression><![CDATA["/home/ronaldo/workspace/odontonew/src/main/webapp/WEB-INF/report/"]]></defaultValueExpression>
    </parameter>
    <parameter name="totaltt" class="java.lang.Double"/>
    <parameter name="dentista" class="br.com.odontonew.bean.Dentista"/>
    <parameter name="historicosCaixaDentista" class="java.lang.Object"/>
    <parameter name="historicosPagamentoOrcamento" class="java.lang.Object"/>
    <parameter name="parcelasAVencerHoje" class="java.lang.Object"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="nomePaciente" class="java.lang.String">
        <fieldDescription><![CDATA[orcamento.paciente.pessoaFisica.nome]]></fieldDescription>
    </field>
    <field name="dataHoraConsulta" class="java.sql.Timestamp">
        <fieldDescription><![CDATA[dataHoraAgendada]]></fieldDescription>
    </field>
    <field name="idConsulta" class="java.lang.Integer">
        <fieldDescription><![CDATA[id]]></fieldDescription>
    </field>
    <field name="nomeProcedimento" class="java.lang.String">
        <fieldDescription><![CDATA[itens.itemTabelaProcedimento.procedimento.nome]]></fieldDescription>
    </field>
    <field name="isConcluido" class="java.lang.Boolean">
        <fieldDescription><![CDATA[itens.concluido]]></fieldDescription>
    </field>
    <group name="consulta">
        <groupExpression><![CDATA[$F{idConsulta}]]></groupExpression>
        <groupHeader>
            <band height="33">
                <textField isBlankWhenNull="true">
                    <reportElement x="8" y="16" width="276" height="14" uuid="fd8d4206-2b32-4619-a340-95b4357b6a1a"/>
                    <textElement>
                        <font isBold="true"/>
                    </textElement>
                    <textFieldExpression><![CDATA[$F{nomePaciente}]]></textFieldExpression>
                </textField>
                <textField pattern="dd/MM/yyyy h.mm a" isBlankWhenNull="true">
                    <reportElement x="292" y="16" width="184" height="14" uuid="e7b1cb6b-c4c4-42ab-b028-69e720f43f1f"/>
                    <textElement>
                        <font isBold="true"/>
                    </textElement>
                    <textFieldExpression><![CDATA[$F{dataHoraConsulta}]]></textFieldExpression>
                </textField>
                <staticText>
                    <reportElement x="9" y="5" width="149" height="12" uuid="bf06788d-c15a-4547-8a6e-df2ae3be70ea"/>
                    <textElement>
                        <font size="8"/>
                    </textElement>
                    <text><![CDATA[Paciente da Consulta]]></text>
                </staticText>
                <staticText>
                    <reportElement x="292" y="5" width="149" height="12" uuid="4d788cff-e015-4085-a320-8924a6a6b48c"/>
                    <textElement>
                        <font size="8"/>
                    </textElement>
                    <text><![CDATA[Data e Hora da Consulta]]></text>
                </staticText>
            </band>
        </groupHeader>
    </group>
    <background>
        <band/>
    </background>
    <title>
        <band height="90" splitType="Stretch">
            <subreport>
                <reportElement stretchType="RelativeToBandHeight" x="0" y="0" width="575" height="90" uuid="0999674d-9841-41dd-97c2-226b2186b45e"/>
                <subreportParameter name="pathLogomarca">
                    <subreportParameterExpression><![CDATA[$P{pathLogomarca}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="cidade">
                    <subreportParameterExpression><![CDATA[$P{cidade}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="titulo">
                    <subreportParameterExpression><![CDATA[$P{titulo}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="cep">
                    <subreportParameterExpression><![CDATA[$P{cep}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="estado">
                    <subreportParameterExpression><![CDATA[$P{estado}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="usuario">
                    <subreportParameterExpression><![CDATA[$P{usuario}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="razaoSocial">
                    <subreportParameterExpression><![CDATA[$P{razaoSocial}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="endereco">
                    <subreportParameterExpression><![CDATA[$P{endereco}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportExpression><![CDATA[$P{pathSubreport}+"headerTemplate.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </title>
    <columnHeader>
        <band height="76">
            <rectangle>
                <reportElement x="0" y="27" width="575" height="49" backcolor="#DFDCDC" uuid="4e1f0879-74cc-46bf-8fb2-bb60ea002018"/>
                <graphicElement>
                    <pen lineWidth="0.0"/>
                </graphicElement>
            </rectangle>
            <staticText>
                <reportElement x="416" y="57" width="140" height="14" uuid="afd4b28f-8b51-43d1-a9a2-c4acbb1f6c63"/>
                <textElement textAlignment="Center">
                    <font isBold="true"/>
                </textElement>
                <text><![CDATA[Concluído]]></text>
            </staticText>
            <staticText>
                <reportElement x="7" y="57" width="397" height="14" uuid="2c8deaa8-9d46-4c31-a542-e41b7f959615"/>
                <textElement>
                    <font isBold="true"/>
                </textElement>
                <text><![CDATA[Procedimento]]></text>
            </staticText>
            <staticText>
                <reportElement x="9" y="34" width="397" height="14" uuid="6578bf15-8e39-4a0d-9fc6-5c45fb5ad566"/>
                <textElement>
                    <font isBold="true" isItalic="true" isUnderline="false"/>
                </textElement>
                <text><![CDATA[Consultas Realizadas]]></text>
            </staticText>
            <textField pattern="dd/MM/yyyy" isBlankWhenNull="true">
                <reportElement x="120" y="5" width="165" height="14" uuid="4a835664-78da-4231-b7de-a21b730b4a7e"/>
                <textFieldExpression><![CDATA[$P{dataFechamento}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="6" y="5" width="112" height="14" uuid="8420da3e-43c6-49a6-a688-89d50b5095a7"/>
                <textElement>
                    <font isBold="true"/>
                </textElement>
                <text><![CDATA[Data Fechamento:]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="21">
            <textField isBlankWhenNull="true">
                <reportElement x="10" y="4" width="394" height="14" uuid="0f1109a2-30d7-4789-bb6f-54d066856cf3"/>
                <textFieldExpression><![CDATA[$F{nomeProcedimento}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true">
                <reportElement x="425" y="1" width="131" height="14" uuid="6b67a6ee-6732-48b6-b79e-12f6e371c35e"/>
                <textFieldExpression><![CDATA[$F{isConcluido} ? "Sim" : "Não"]]></textFieldExpression>
            </textField>
        </band>
        <band height="173">
            <subreport>
                <reportElement x="0" y="0" width="575" height="73" uuid="871e12c8-2633-4d76-8d65-ce253710c4eb"/>
                <dataSourceExpression><![CDATA[$P{historicosPagamentoOrcamento}]]></dataSourceExpression>
                <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "rf002_historicosPagamentoOrcamento.jasper"]]></subreportExpression>
            </subreport>
            <subreport>
                <reportElement x="0" y="94" width="575" height="69" uuid="338fd0af-a2ca-453e-8777-0f49698ebb44"/>
                <dataSourceExpression><![CDATA[$P{historicosCaixaDentista}]]></dataSourceExpression>
                <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "rf002_historicosCaixa.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </detail>
    <lastPageFooter>
        <band height="185" splitType="Stretch">
            <textField evaluationTime="Report">
                <reportElement x="516" y="155" width="40" height="20" uuid="3cd272a2-adde-48f0-9f1e-5d7f007b9a1f"/>
                <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="436" y="155" width="80" height="20" uuid="7cc86ec7-b620-4c95-9147-1410b1a22054"/>
                <textElement textAlignment="Right"/>
                <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
            </textField>
        </band>
    </lastPageFooter>
</jasperReport>

经过大量研究后,我发现我的“主报告”和“子报道”的概念是错误的。当我们有一个“主报告”(与主数据源相关联)时,正确的是所有“子报告”都与此直接关联。所以,我创建了3个子报表并传递所有数据源,如'param'。在JasperManagerFillReport中,我传递了一个“JREmptyDataSource”以避免空白页面,因为“主数据源”没有任何内容。

1 个答案:

答案 0 :(得分:0)

您可以尝试将WhenNoData属性设置为NoDataSection。然后,在No Data频段中添加您想要的内容。

另外,当您作为dataSourceExpression发送的参数为空(如果是)时,检查子报表会发生什么。