JasperReports:将列表列表作为数据源传递 [英] JasperReports: Passing in a list of lists as a datasource

查看:252
本文介绍了JasperReports:将列表列表作为数据源传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用不同对象的列表填充一些子报表。基本上我可以说我有以下几点:

二手车的子报表

新车的子报表

I need to populate a few subreports with lists of different objects. Basically lets say i have the following:
Subreport on used Vehicles
Subreport on new Vehicles

我创建了一个车辆bean类,其变量为字符串,并为其创建getter和setter方法。然后在我的数据源中,我将 List< List< String>> 作为detailRows传递。 detailRows包含新车辆列表和二手车辆列表。所以我要说,我在数据源中传递detailRows。

问题是如何将这两个列表传递给两个子报告?我可以使用
new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($ F {newVehiclesList})作为子报表1和$ b $的数据源b new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($ F {usedVehiclesList})作为子报表2的数据源?

有吗除了我提到的以外还有什么需要做的吗?我需要创建并传递任何变量吗?是否正确使用了上面列出的列表列表,还是 $ F {detailRows} .get(0)

I create a vehicle bean class with variables as strings and create getter and setter methods for the same. Then in my datasource I pass in a List<List<String>> as detailRows. detailRows contains a list for new vehicles and a list for used vehicles. So lets say, i pass detailRows in the data source.
Question is how do i pass these two lists to the two sub-reports? Can i use new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{newVehiclesList}) as a datasource for sub report 1 and new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{usedVehiclesList}) as datasource for sub report 2?
Is there anything else that needs to be done apart from what i mentioned? Do i need to create and pass any variables? Is the appropriate use of the list of lists as i have listed above or is it $F{detailRows}.get(0)?

我在主报表中创建了一个字段detailRows作为类型列表。然后我将以下内容传递给子报表数据源表达式, new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($ F {detailRows}
有没有我可以将 newVehiclesList 从detailRows传递到子报告吗?

I created a field detailRows in the main report as type list. I then pass the following to the subreport data source expression, new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{detailRows} Is there any way i can pass the newVehiclesList from detailRows to the sub-report?

谢谢!

推荐答案

选择您的SubReport,您可以将属性连接类型设置为使用数据源表达式,并在您设置的属性数据源表达式中设置这个:

Selecting your SubReport you can set the property "Connection type" as "Use a data source expression" and inside the property "Data Source Expression" you set this:

new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{yourFieldHere})

您的yourFieldHere是一个列表(不要忘记将字段属性中的字段类设置为java.util.List也是)

Where your "yourFieldHere" is a list (don't forget to set the "Field Class" inside your field properties as a java.util.List as well)

这篇关于JasperReports:将列表列表作为数据源传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆