简体   繁体   English

报告中有两个数据源

[英]Two DataSource in report

I have to make a report in jasperReports 我必须在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 List1 wich实际有效
List2 that is my other list List2是我的另一个列表
How can i pass this other list? 我该如何通过其他清单? Also i have a subreport in my .jxrml but this two list are of differents object 我的.jxrml中也有一个子报表,但是这两个列表具有不同的对象

You can send the second one as a parameter. 您可以发送第二个作为参数。

parametros.put("dataSource2", List2 ); parametros.put(“ dataSource2”,List2);

In the report set the parameter type as 在报告中,将参数类型设置为

net.sf.jasperreports.engine.data.JRBeanCollectionDataSource net.sf.jasperreports.engine.data.JRBeanCollectionDataSource

You can use $P{dataSource2} as a datasource to a subreport, in a Table, in a List. 您可以将$ P {dataSource2}用作表中列表中子报告的数据源。

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元素,添加以下行进行设置:

<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) 1.声明一个子数据集(假设“代码”和“标题”是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") 2.实际表-将subDataset设置为具有您声明的子表的名称(“ Table Dataset 1”),并将REPORT_DATA_SOURCE参数作为包含List2的参数(“ dataSource2”)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM