how to fill out a .jasper report that contains sub reports with a HashMap?

0

I must fill out a .jrxml template that contains sub reports inside:

That is, several sections that show certain information and some will be conditioned to show the information. However, I am ignorant of the management of templates for the generation of reports, I have no idea how to send the parameters to said template.

Can someone guide me in this practice?

The template is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.5.1.final using JasperReports Library version 6.5.1  -->
<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="pruebaMF" pageWidth="612" pageHeight="792" whenNoDataType="NoPages" columnWidth="572" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="3478e215-5465-433f-babf-544956062915">
    <property name="ireport.zoom" value="1.5"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <property name="ireport.scriptlethandling" value="0"/>
    <property name="ireport.encoding" value="UTF-8"/>
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <import value="net.sf.jasperreports.engine.*"/>
    <import value="java.util.*"/>
    <import value="net.sf.jasperreports.engine.data.*"/>
    <style name="importeStyle">
        <conditionalStyle>
            <conditionExpression><![CDATA[new Boolean("Importe".equalsIgnoreCase(($F{label} != null)? $F{label}.trim() : "") || "Importe:".equalsIgnoreCase(($F{label} != null)? $F{label}.trim() : "") || (($F{label} != null)? $F{label}.trim() : "").indexOf("Importe") > -1)]]></conditionExpression>
            <style forecolor="#006EC1"/>
        </conditionalStyle>
    </style>
    <subDataset name="Dataset1" uuid="04cddaeb-a294-4127-915a-4e20525a617a">
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
        <queryString>
            <![CDATA[]]>
        </queryString>
    </subDataset>
    <parameter name="nombreUsuario" class="java.lang.String"/>
    <parameter name="titulo" class="java.lang.String"/>
    <parameter name="tipoComprobante" class="java.lang.String"/>
    <parameter name="SUBREPORT_DIR" class="java.lang.String">
        <defaultValueExpression><![CDATA["report/"]]></defaultValueExpression>
    </parameter>
    <parameter name="pie" class="java.lang.String"/>
    <parameter name="rutaImagen" class="java.lang.String"/>
    <parameter name="rutaImagenIconoTitulo" class="java.lang.String"/>
    <parameter name="textoLegal" class="java.lang.String"/>
    <parameter name="fechaSistema" class="java.lang.String"/>
    <parameter name="avisoImportante" class="java.lang.String"/>
    <parameter name="subtitulo" class="java.lang.String"/>
    <parameter name="tituloInv" class="java.lang.String"/>
    <field name="input" class="java.lang.String"/>
    <field name="label" class="java.lang.String"/>
    <field name="mapaVacioParaSubreportCabecera" class="java.util.ArrayList">
        <fieldDescription><![CDATA[mapaVacioParaSubreportCabecera]]></fieldDescription>
    </field>
    <field name="mapa1" class="java.util.ArrayList">
        <fieldDescription><![CDATA[mapa1]]></fieldDescription>
    </field>
    <field name="mapa2" class="java.util.ArrayList">
        <fieldDescription><![CDATA[mapa2]]></fieldDescription>
    </field>
    <field name="mapa3" class="java.util.ArrayList">
        <fieldDescription><![CDATA[mapa3]]></fieldDescription>
    </field>
    <field name="mapa4" class="java.util.ArrayList">
        <fieldDescription><![CDATA[mapa4]]></fieldDescription>
    </field>
    <field name="mapa5" class="java.util.ArrayList">
        <fieldDescription><![CDATA[mapa5]]></fieldDescription>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="120" splitType="Stretch">
            <subreport isUsingCache="false">
                <reportElement key="pdfGenerico_subreportCabecera" x="-20" y="-20" width="612" height="140" uuid="f7065bff-06cb-485d-acb6-8248b6c61c32"/>
                <subreportParameter name="fechaSistema">
                    <subreportParameterExpression><![CDATA[$P{fechaSistema}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="titulo">
                    <subreportParameterExpression><![CDATA[$P{titulo}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="tipoComprobante">
                    <subreportParameterExpression><![CDATA[$P{tipoComprobante}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="rutaImagen">
                    <subreportParameterExpression><![CDATA[$P{rutaImagen}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="rutaImagenIconoTitulo">
                    <subreportParameterExpression><![CDATA[$P{rutaImagenIconoTitulo}]]></subreportParameterExpression>
                </subreportParameter>
                <subreportParameter name="nombreUsuario">
                    <subreportParameterExpression><![CDATA[$P{nombreUsuario}]]></subreportParameterExpression>
                </subreportParameter>
                <dataSourceExpression><![CDATA[new JRBeanCollectionDataSource($F{mapaVacioParaSubreportCabecera})]]></dataSourceExpression>
                <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "pdfGenerico_subreportCabecera.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </title>
    <detail>
        <band height="27" splitType="Stretch">
            <line>
                <reportElement isPrintRepeatedValues="false" x="36" y="0" width="500" height="1" isPrintInFirstWholeBand="true" forecolor="#CCCCCC" uuid="436a41d1-b7e5-4310-8679-5e0b4a5af082"/>
                <graphicElement>
                    <pen lineWidth="0.5"/>
                </graphicElement>
            </line>
            <subreport isUsingCache="false">
                <reportElement x="36" y="5" width="500" height="21" uuid="b98d4a54-66f1-4cac-bb75-798b771f6e8b"/>
                <dataSourceExpression><![CDATA[new JRBeanCollectionDataSource($F{mapa1})]]></dataSourceExpression>
                <subreportExpression><![CDATA[$P{SUBREPORT_DIR} +"pdfsubReport_comprog.jasper"]]></subreportExpression>
            </subreport>
        </band>
        <band height="34">
            <subreport isUsingCache="false" overflowType="Stretch">
                <reportElement x="35" y="6" width="500" height="21" uuid="6f68c68c-20cc-42f3-8dcb-cf22b08045cb"/>
                <dataSourceExpression><![CDATA[new JRBeanCollectionDataSource($F{mapa2})]]></dataSourceExpression>
                <subreportExpression><![CDATA[$P{SUBREPORT_DIR} +"pdfsubReport_comprog.jasper"]]></subreportExpression>
            </subreport>
        </band>
        <band height="45">
            <subreport isUsingCache="false">
                <reportElement x="36" y="4" width="500" height="21" uuid="773c6ceb-c8fa-4609-b199-0e0b86148123"/>
                <dataSourceExpression><![CDATA[new JRBeanCollectionDataSource($F{mapa3})]]></dataSourceExpression>
                <subreportExpression><![CDATA[$P{SUBREPORT_DIR} +"pdfsubReport_comprog.jasper"]]></subreportExpression>
            </subreport>
            <subreport isUsingCache="false">
                <reportElement x="203" y="31" width="161" height="10" uuid="576d64f9-e54c-4cfa-ad44-8b2456344750"/>
                <connectionExpression><![CDATA[new JRBeanCollectionDataSource($F{mapa5})]]></connectionExpression>
                <subreportExpression><![CDATA[$P{SUBREPORT_DIR} +"simu_comprog.jasper"]]></subreportExpression>
            </subreport>
        </band>
        <band height="32">
            <subreport isUsingCache="false">
                <reportElement x="36" y="6" width="500" height="21" uuid="7a858acb-70eb-4e19-b7c4-d0d729f46333"/>
                <dataSourceExpression><![CDATA[new JRBeanCollectionDataSource($F{mapa4})]]></dataSourceExpression>
                <subreportExpression><![CDATA[$P{SUBREPORT_DIR} +"pdfsubReport_comprog.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </detail>
    <lastPageFooter>
        <band height="109" splitType="Stretch">
            <textField>
                <reportElement x="0" y="90" width="557" height="19" uuid="cc7f6679-429b-48b2-aeab-12e1582a4140"/>
                <textElement textAlignment="Center">
                    <font fontName="Arial" isBold="true" isUnderline="false" isStrikeThrough="false"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{pie}]]></textFieldExpression>
            </textField>
            <textField isBlankWhenNull="true">
                <reportElement x="36" y="25" width="502" height="51" uuid="d7a25b32-9503-408c-a900-665396cd58ec"/>
                <textElement verticalAlignment="Bottom"/>
                <textFieldExpression><![CDATA[$P{textoLegal}]]></textFieldExpression>
            </textField>
            <line>
                <reportElement x="36" y="4" width="502" height="1" isPrintWhenDetailOverflows="true" forecolor="#CCCCCC" uuid="436a41d1-b7e5-4310-8679-5e0b4a5af082">
                    <printWhenExpression><![CDATA[$P{textoLegal}.equals( new String() )]]></printWhenExpression>
                </reportElement>
                <graphicElement>
                    <pen lineWidth="0.5"/>
                </graphicElement>
            </line>
            <textField isBlankWhenNull="true">
                <reportElement x="36" y="5" width="502" height="14" uuid="d7a25b32-9503-408c-a900-665396cd58ec"/>
                <textElement textAlignment="Center" verticalAlignment="Bottom">
                    <font fontName="SansSerif" size="11" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{avisoImportante}]]></textFieldExpression>
            </textField>
        </band>
    </lastPageFooter>
</jasperReport>

In java, I'm filling a map. Within this map I manage 4 more maps:

public Map<String, Object> rellenaMap(){


final Map<String, Object> mapa = new LinkedHashMap<String, Object>(6);
String constante = "Opercacion programada"; 
String bandera = this.getEsPro();
String marca = this.getIsScheledPeriodic();
String importeIngreso="";
try {
    imporIn = NumberFormatUtil.getCurrencyLocale(this.getImporI(), Currency.getInstance(LocaleUtil.cargaLocale()));
} catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
final Map<String, Object> mapa1 = new LinkedHashMap<String, Object>();
final Map<String, Object> mapa2 = new LinkedHashMap<String, Object>();
final Map<String, Object> mapa3 = new LinkedHashMap<String, Object>();
final Map<String, Object> mapa4 = new LinkedHashMap<String, Object>();

   mapa1.put("inv.cE",this.getNCuaC());
   mapa1.put("inv.inv",imporIn);
   mapa1.put("inv.fInv",this.getFSeD());
   mapa1.put("inv.preActual", this.getPr());
   mapa1.put("inv.titOpe",this.getTitC());
   mapa1.put("inv.serie",this.getSer());

   mapa.put("inv.mapa1", mapa1);

   mapa2.put("inv.cuen",this.numCCort);
   mapa2.put("inv.cont",this.contInv);   
   mapa2.put("inv.serv",this.servinvf);

   mapa.put("inv.mapa2", mapa2);


   if (marca.equalsIgnoreCase("OK")){

   mapa3.put("opPer.coFs.frec",getPeriodic()); 
   mapa3.put("opPer.coFs.impor",getMonOperadoProg());
   mapa3.put("opPer.coFs.fecha_inicio",getStartDate()); 
   mapa3.put("opPer.coFs.repeticionesLabel",getFecter()); 

   mapa3.put("opPer.coFs.repeticionesLabel",getHowOften());

   mapa.put("inv.mapa3", mapa3);



   }



    if (bandera.equalsIgnoreCase("s")) {

        mapa4.put("inv.coVaFs.folProg", this.getFolOper());
        mapa4.put("inv.fecProg", this.getFecOpe());
        mapa4.put("inv.coVaFs.horaProgramada", this.getHrProg());
        mapa4.put("inv.coVaFs.fechaProgramada", this.getFecProg());

        mapa.put("inv.mapa4", mapa4);
    } else {

        mapa4.put("inv.folOpera", this.getFolInt());
        mapa4.put("inv.feOpera",this.getFeOper());

        mapa.put("inv.mapa4", mapa4);

    }


return mapa;
}

However the result is the following:

Just put the title of the map and the syntax chain of the map in question:

Opera : {inv.cE =15325474,
         inv.inv =$200.00}

programa : { inv.cuen=234824,
             inv.cont=745264}

I do not know if I'm not sending the maps correctly but it's supposed to be something like this:

mapa1

  • label: data.
  • label: data.
  • label: data.
  • label: data.

mapa2

  • label: data.
  • label: data.
  • label: data.
  • label: data.

mapa3

  • label: data.
  • label: data.
  • label: data.
  • label: data.

mapa4

  • label: data.
  • label: data.
  • label: data.
  • label: data.
asked by Nagisa 19.04.2018 в 02:28
source

0 answers