List of Objects in Sub Sub report

0

i'm trying to pass a list of objects from Sub report to Sub sub report.

From JAVA i'm passing a List<A> to master.jrxml.

Each A object are filled in a subreport.

Each A object have another list ( let's call it Object B).

So i have to pass List<B> to sub sub report.

I a lot of things but nothing worked for now..

My code is:

JAVA (the most relevant part)

..
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"?>
<!-- Created with Jaspersoft Studio version 6.14.0.final using JasperReports Library version 6.14.0-2ab0d8625be255bf609c78e1181801213e51db8f  -->
<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"/>
    <field name="origen" class="java.lang.String"/>
    <field name="coordenada" class="es.sigma.imina.modelo.perimetro.Coordenada"/>
    <field name="conductividadElectrica" class="java.lang.Float"/>
    <field name="ph" class="java.lang.Integer"/>
    <field name="afeccionesOrigenAguasSup" class="java.lang.String"/>
    <field name="afeccionesDescFoco" class="java.lang.String"/>
    <field name="afeccionesOrigen" class="java.lang.String"/>
    <field name="herramientaMedida" class="java.lang.String"/>
    <field name="muestraActual" class="es.sigma.imina.modelo.tomamuestras.Muestra">
        <fieldDescription><![CDATA[_THIS]]></fieldDescription>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="615" 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>
            <staticText>
                <reportElement x="142" y="170" width="141" height="20" uuid="ca41b3db-781d-4ce9-b7a9-aa52c634fe7a"/>
                <box topPadding="3">
                    <pen lineWidth="1.0" lineStyle="Solid"/>
                </box>
                <textElement>
                    <font fontName="Noto Sans HK Black" isBold="true"/>
                </textElement>
                <text><![CDATA[Y:]]></text>
            </staticText>
            <staticText>
                <reportElement x="3" y="170" width="138" height="20" uuid="66f62554-0a99-4b0e-af11-bcd66d355845"/>
                <box topPadding="3">
                    <pen lineWidth="1.0" lineStyle="Solid"/>
                </box>
                <textElement>
                    <font fontName="Noto Sans HK Black" isBold="true"/>
                </textElement>
                <text><![CDATA[X:]]></text>
            </staticText>
            <staticText>
                <reportElement x="3" y="150" width="280" height="20" uuid="0e6a8401-13fa-4b2d-8db2-453600ca585c"/>
                <box topPadding="3">
                    <pen lineWidth="1.0" lineStyle="Solid"/>
                </box>
                <textElement>
                    <font fontName="Noto Sans HK Black" isBold="true"/>
                </textElement>
                <text><![CDATA[Coordenada UTM - ETR89 | Huso: 30]]></text>
            </staticText>
            <staticText>
                <reportElement x="2" y="210" width="90" height="30" forecolor="#098250" uuid="92e31fba-48e9-45f4-8012-4a3cc5f2fa35"/>
                <textElement>
                    <font fontName="Noto Sans HK Black" size="14"/>
                </textElement>
                <text><![CDATA[Fotografías:]]></text>
            </staticText>
            <staticText>
                <reportElement x="4" y="240" width="67" height="30" forecolor="#098250" uuid="d177d92f-1788-4360-ab83-5a485a0f879a"/>
                <textElement>
                    <font fontName="Noto Sans HK Black" size="14"/>
                </textElement>
                <text><![CDATA[Informe:]]></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="22" y="170" width="119" height="20" uuid="452243aa-9016-45ab-afba-f860b20647ca">
                    <property name="com.jaspersoft.studio.unit.width" value="px"/>
                </reportElement>
                <box topPadding="3"/>
                <textFieldExpression><![CDATA[$F{coordenada}.getxUTM()]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="162" y="170" width="118" height="20" uuid="9ea9437b-5f04-4268-b1e9-928232408476"/>
                <box topPadding="3" leftPadding="0"/>
                <textFieldExpression><![CDATA[$F{coordenada}.getyUTM()]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="2" y="70" width="251" height="30" forecolor="#098250" uuid="a1d8344c-0f79-4042-aaf7-889f5877d008"/>
                <textElement>
                    <font fontName="Noto Sans HK Black" size="14" isUnderline="true"/>
                </textElement>
                <text><![CDATA[Localización muestra]]></text>
            </staticText>
            <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>
            <staticText>
                <reportElement x="0" y="0" width="540" height="30" uuid="353fc1ea-d516-487e-bcb8-442dba933024">
                    <property name="com.jaspersoft.studio.unit.x" value="pixel"/>
                    <property name="com.jaspersoft.studio.unit.width" value="px"/>
                </reportElement>
                <box>
                    <pen lineWidth="0.5"/>
                    <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textElement textAlignment="Center" verticalAlignment="Top" rotation="None">
                    <font fontName="Noto Sans HK Black" size="18"/>
                    <paragraph lineSpacingSize="1.0"/>
                </textElement>
                <text><![CDATA[Toma de muestras]]></text>
            </staticText>
            <staticText>
                <reportElement x="2" y="360" width="155" height="20" uuid="03ed11de-5770-408e-80b5-caa033849918">
                    <printWhenExpression><![CDATA[$F{origen}.equals("A")]]></printWhenExpression>
                </reportElement>
                <textElement>
                    <font fontName="Noto Sans HK Black" isBold="true"/>
                </textElement>
                <text><![CDATA[Origen de aguas superficiales:]]></text>
            </staticText>
            <staticText>
                <reportElement x="282" y="360" width="44" height="20" uuid="9791b81f-4e38-462b-99df-62e14d7e5665">
                    <printWhenExpression><![CDATA[$F{origen}.equals("A")]]></printWhenExpression>
                </reportElement>
                <textElement>
                    <font fontName="Noto Sans HK Black" isBold="true"/>
                </textElement>
                <text><![CDATA[Origen:]]></text>
            </staticText>
            <staticText>
                <reportElement x="2" y="380" width="155" height="20" uuid="57b94d9b-45a7-4be2-812d-c9f229b22fbb">
                    <printWhenExpression><![CDATA[$F{origen}.equals("A")]]></printWhenExpression>
                </reportElement>
                <textElement>
                    <font fontName="Noto Sans HK Black" isBold="true"/>
                </textElement>
                <text><![CDATA[Descripción del foco:]]></text>
            </staticText>
            <staticText>
                <reportElement x="2" y="450" width="251" height="20" forecolor="#092382" uuid="ad909356-568f-4d60-a1de-860a9e31d738">
                    <printWhenExpression><![CDATA[$F{origen}.equals("A")]]></printWhenExpression>
                </reportElement>
                <textElement>
                    <font fontName="Noto Sans HK Black" size="11"/>
                </textElement>
                <text><![CDATA[En campo (mediante sondas)]]></text>
            </staticText>
            <staticText>
                <reportElement x="282" y="510" width="130" height="20" uuid="dc6ecadd-fb4f-40d5-b2b8-49632fa18649">
                    <printWhenExpression><![CDATA[$F{origen}.equals("A")]]></printWhenExpression>
                </reportElement>
                <textElement>
                    <font fontName="Noto Sans HK Black" isBold="true"/>
                </textElement>
                <text><![CDATA[Conductividad eléctrica:]]></text>
            </staticText>
            <staticText>
                <reportElement x="2" y="480" width="251" height="20" forecolor="#092382" uuid="ee40da12-297b-4bd9-81df-a7919754751c">
                    <printWhenExpression><![CDATA[$F{origen}.equals("A")]]></printWhenExpression>
                </reportElement>
                <textElement>
                    <font fontName="Noto Sans HK Black" size="11"/>
                </textElement>
                <text><![CDATA[En laboratorio]]></text>
            </staticText>
            <staticText>
                <reportElement x="2" y="510" width="25" height="20" uuid="b07264d5-33d0-4c41-bd62-07872f8d7383">
                    <printWhenExpression><![CDATA[$F{origen}.equals("A")]]></printWhenExpression>
                </reportElement>
                <textElement>
                    <font fontName="Noto Sans HK Black" isBold="true"/>
                </textElement>
                <text><![CDATA[PH:]]></text>
            </staticText>
            <textField>
                <reportElement x="2" y="400" width="556" height="50" uuid="2a3dca31-d2f6-4aef-bc4a-b056d5d53dfd">
                    <printWhenExpression><![CDATA[$F{origen}.equals("A")]]></printWhenExpression>
                </reportElement>
                <textFieldExpression><![CDATA[$F{afeccionesDescFoco}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="27" y="510" width="100" height="20" uuid="53ab40e9-5275-42b3-90e7-7fbb6f82640d">
                    <printWhenExpression><![CDATA[$F{origen}.equals("A")]]></printWhenExpression>
                </reportElement>
                <textFieldExpression><![CDATA[$F{ph}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="412" y="510" width="100" height="20" uuid="136de3f6-2461-49a9-8fcb-08d9583db066">
                    <printWhenExpression><![CDATA[$F{origen}.equals("A")]]></printWhenExpression>
                </reportElement>
                <textFieldExpression><![CDATA[$F{conductividadElectrica}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="157" y="360" width="100" height="20" uuid="d07c1c75-3173-4ae5-b94e-b0e270a404c2">
                    <printWhenExpression><![CDATA[$F{origen}.equals("A")]]></printWhenExpression>
                </reportElement>
                <textFieldExpression><![CDATA[$F{afeccionesOrigenAguasSup}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="326" y="360" width="100" height="20" uuid="7d4dc43d-c5ab-4dff-b687-f9ade2d6f522">
                    <printWhenExpression><![CDATA[$F{origen}.equals("A")]]></printWhenExpression>
                </reportElement>
                <textFieldExpression><![CDATA[$F{afeccionesOrigen}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="4" y="285" width="256" height="25" forecolor="#098250" uuid="b3c8b26d-d548-4407-97c9-c68c5849da5f">
                    <printWhenExpression><![CDATA[$F{origen}.equals("A")]]></printWhenExpression>
                </reportElement>
                <textElement>
                    <font fontName="Noto Sans HK Black" size="14"/>
                </textElement>
                <text><![CDATA[Muestreo analítico de las Aguas:]]></text>
            </staticText>
            <staticText>
                <reportElement x="5" y="320" width="251" height="20" forecolor="#092382" uuid="817ef480-f2e5-40eb-a5fc-d27bdf38889f">
                    <printWhenExpression><![CDATA[$F{origen}.equals("A")]]></printWhenExpression>
                </reportElement>
                <textElement>
                    <font fontName="Noto Sans HK Black" size="11"/>
                </textElement>
                <text><![CDATA[Afecciones Contaminantes]]></text>
            </staticText>
            <staticText>
                <reportElement x="4" y="285" width="256" height="25" forecolor="#098250" uuid="646e6fe1-e5a6-47b9-aa13-000177c1f440">
                    <printWhenExpression><![CDATA[$F{origen}.equals("B")]]></printWhenExpression>
                </reportElement>
                <textElement>
                    <font fontName="Noto Sans HK Black" size="14"/>
                </textElement>
                <text><![CDATA[Composición química de lodos:]]></text>
            </staticText>
            <textField>
                <reportElement x="162" y="320" width="110" height="19" uuid="6e229dc8-97df-464d-b611-7f75c6245ecc">
                    <printWhenExpression><![CDATA[$F{origen}.equals("B")]]></printWhenExpression>
                </reportElement>
                <textFieldExpression><![CDATA[$F{herramientaMedida}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="5" y="320" width="157" height="20" uuid="1a0d02d4-76e1-42a6-951e-6332f9e723e7">
                    <printWhenExpression><![CDATA[$F{origen}.equals("B")]]></printWhenExpression>
                </reportElement>
                <textElement>
                    <font fontName="Noto Sans HK Black" isBold="true"/>
                </textElement>
                <text><![CDATA[Herramienta de medida:]]></text>
            </staticText>
            <subreport>
                <reportElement x="20" y="540" width="231" height="71" uuid="12780bc3-3699-429d-9e94-146d8eaf5042"/>
                <subreportParameter name="subReportTomaMuestra">
                    <subreportParameterExpression><![CDATA[$P{subReportTomaMuestra}]]></subreportParameterExpression>
                </subreportParameter>
                <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{muestraActual}.getMuestrasMetales())
 
]]></dataSourceExpression>
                <subreportExpression><![CDATA[$P{subReportTomaMuestra} + "muestraAnaliticaBLab.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </detail>
</jasperReport>
 

SUB SUBREPORT

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.14.0.final using JasperReports Library version 6.14.0-2ab0d8625be255bf609c78e1181801213e51db8f  -->
<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="muestraAnaliticaBLab" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="840f8ca2-eb86-4ae0-8886-2eed2f4ad171">
    <property name="com.jaspersoft.studio.unit." value="pixel"/>
    <property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
    <subDataset name="Empty Dataset1" uuid="6c1d7f54-b5f9-4bf7-ac95-38d180efe903"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="determinacionConcentracion" class="java.lang.Double"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="30" splitType="Stretch">
            <staticText>
                <reportElement x="-10" y="0" width="100" height="30" uuid="13c15edc-c478-4475-a5e3-3a9f8d1277a6"/>
                <text><![CDATA[PRUEBA]]></text>
            </staticText>
            <textField>
                <reportElement x="190" y="0" width="100" height="30" uuid="c2994f70-7959-48f4-a0ef-ab9b9f4e8dc0"/>
                <textFieldExpression><![CDATA[$F{determinacionConcentracion}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="90" y="0" width="100" height="30" uuid="3ed51052-c0b0-4dfd-929f-aecbd38a4834"/>
                <text><![CDATA[determinacionConcentracion]]></text>
            </staticText>
        </band>
    </detail>
</jasperReport>

Now i'm trying passing a _THIS as DatasourceExpresion, but it does not work...

Please, ignore the simple desing for the jrxml, i just remove the not relevant information for not do this so long. Any idea?

 
miguelangelgea's picture
Joined: Oct 6 2020 - 3:54am
Last seen: 1 month 6 days ago

using _THIS did the trick

miguelangelgea - 1 month 2 weeks ago

0 Answers:

No answers yet
Feedback