0

I have to make a report in jasperReports
I fill my initial report with a DataSource like this

File mainJasper = new File( servletContext.getRealPath("/WEB-INF/prueba.jasper") );                             

            Map<String,Object> parametros = new HashMap<String, Object>();
            parametros.put("numLista", numLista );
            parametros.put("txtDestino", pas.getLista().getCiudadDestino());
            parametros.put("txtFecLlegada", pas.getLista().getFecLleLista().toString());
            parametros.put("txtProcedencia", pas.getLista().getCiudadProcedencia() );
            parametros.put("txtNombres", con.getPersona().getNomPersona() );
            parametros.put("txtFecNac", con.getPersona().getFecNacPersona().toString() );
            parametros.put("txtTipoDoc", con.getPersona().getParametrica().getNomParametrica());
            parametros.put("txtNroBrevete", con.getNumBrevConductor() );
            parametros.put("txtOcupacion", con.getPersona().getProPersona() );
            parametros.put("txtApellidos", con.getPersona().getApePatPersona() + " " +con.getPersona().getApeMatPersona()  );
            parametros.put("txtDomicilio", con.getPersona().getDirPersona() );
            parametros.put("txtNumDoc", con.getPersona().getNumDoc() );
            parametros.put("txtNacionalidad", con.getPersona().getPais().getNomPais() );
            parametros.put("txtEstCivil", con.getPersona().getEstCivPersona() );                            


            JasperReport mainReporte = (JasperReport) JRLoader.loadObject(mainJasper);
            JasperPrint mainPrint = JasperFillManager.fillReport(mainReporte, parametros, new JRBeanCollectionDataSource(List1));                              

            JRExporter exporter = new JRPdfExporter();              
            exporter.setParameter(JRExporterParameter.JASPER_PRINT, mainPrint);
            exporter.setParameter(JRExporterParameter.OUTPUT_FILE, new java.io.File("new.pdf")); 
            exporter.exportReport(); 

that code works fine, but i have another list, and i want to have two details in my report

My List are
List1 wich actually works
List2 that is my other list
How can i pass this other list? Also i have a subreport in my .jxrml but this two list are of differents object

Alex K
  • 22,315
  • 19
  • 108
  • 236
MitoCode
  • 319
  • 2
  • 10
  • 25
  • Possible duplicate http://stackoverflow.com/questions/15534664/how-to-dynamically-add-multiple-pieces-of-data-in-jasper-reports – sanBez Feb 27 '14 at 09:06

1 Answers1

1

You can send the second one as a parameter.

parametros.put("dataSource2", List2 );

In the report set the parameter type as

net.sf.jasperreports.engine.data.JRBeanCollectionDataSource

You can use $P{dataSource2} as a datasource to a subreport, in a Table, in a List.

Not sure if I understood correctly or it was a different matter,but if you want this to be the datasource of your subreport go to the subreport element on the main report add the following lines to set it:

<subreport>
...
<dataSourceExpression><![CDATA[$P{dataSource2}]]></dataSourceExpression>
...
</subreport>

If this was not what you wanted and you need more specific details, let us know what exactly you will use the second datasource for.

An example - populate a table

1.declare a subdatase (supposing 'code' and 'caption' are the fields of your objects in List2)

 <subDataset name="Table Dataset 1">
            <queryString language="SQL">
                <![CDATA[]]>
            </queryString>
            <field name="code" class="java.lang.String"/>
            <field name="caption" class="java.lang.String"/>
        </subDataset>

2.the actual table - set the subDataset to have the name of the one you declared("Table Dataset 1") and REPORT_DATA_SOURCE parameter to be the parameter which contains your List2 ("dataSource2")

<jr:table ...>
    <datasetRun subDataset="Table Dataset 1">
        <datasetParameter name="REPORT_DATA_SOURCE">
             <datasetParameterExpression><![CDATA[$P{dataSource2}]]></datasetParameterExpression>
        </datasetParameter>
    </datasetRun>
.....
</jr:table>  
Laura
  • 1,552
  • 12
  • 12