Mr.Lanhellas
Mr.Lanhellas

Reputation: 245

Show subreport independent of master datasource (master report) in ireport

Well, i have a Master and a SubReport where in master report i have 2 detail bands. In first detail band i put the "main datasource" (from fillReport), and in detail band 2 i put the subreport (datasource from a param).

My master report is configured to display "All Sections, No Detail" but the problem is that when "main datasource" dont have records the subreport isn't showed. I need show subreport detail independent of content of "main datasource".

How can i do it?

This is my report 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>

SOLUTION

After a lot of research i saw that my concept about "main report" and "subreport" is wrong. When we have a "main report" (associated with a main datasource) the correct is that all "subreport" is directly associated with this. So, i created 3 subreports and pass all datasources like a 'param'. In JasperManagerFillReport i passed a "JREmptyDataSource" to avoid the blank page because "main datasource" don't have any content.

Upvotes: 0

Views: 469

Answers (1)

Laura
Laura

Reputation: 1602

You can try setting WhenNoData property to NoDataSection. Then, in the No Data band add what you want.

Also, check what happens to the subreports when the parameters you send as dataSourceExpression are empty (if they are).

Upvotes: 0

Related Questions