列表与LT;对象>作为子报表的JRBeanCollectionDataSource [英] List<Object> as a JRBeanCollectionDataSource to a Subreport

查看:172
本文介绍了列表与LT;对象>作为子报表的JRBeanCollectionDataSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将List作为JRBeanCollectionDataSource传递给子报表。此处对象的类型为 A B 。对象类型 A 有两个属性: name 地址 ,对象类型 B 包含 位置 属性。

I'm passing a List as a JRBeanCollectionDataSource to a Subreport. Here Object is of Type A and B. The object type A has two properties: name and address and the object type B has the location property.

如果对象的类型为 A ,那么我必须显示 子报告中的名称 地址 。如果类型 B ,那么我必须显示 location

If Object is of type A then I have to display name and address in subreport. And if it is of type B then I have to display location in subreport.

我必须在子报表中访问一种Object,意味着属于哪种类型( A B )?
我已经尝试了很多,但没有找到任何解决方案。

I have to access a type of Object in a subreport, means is of which type (A or B)?. I have tried a lot but not found any solution.

任何人都可以帮助我。
提前致谢。

Can anyone help me please. Thanks in advance.

推荐答案

您有很多选择:

首先:在两个对象中放置一个标记字段,表示此对象A或对象B.

然后在子报表表达式使用这样的三元语句:

First: Put a flag field in both objects stating is this Object A or Object B.
Then in Subreport Expression use a ternary statement like this:

objectType=="ObjectA"?"subreportA.jasper":"subreportB.jasper"

第二名:将子报表名称作为对象内的字段传递本身。

然后在子报告表达式中使用如下字段:

Second: Pass the sub report name as a field inside the object itself.
Then in Subreport Expression use the field like:

$F{subReportName}

第三名:制作两份每个子报表都由其自己的类型填充。如果要显示Subreport A,则填充ObjectA并将ObjectB列表保留为null。在Jasper中,如果填充列表是 NULL ,则不会呈现子报表。

Third: Make two subreports each is populated by its own type. If you want to show "Subreport A" then populate ObjectA and leave ObjectB list as null. In Jasper, if the populating list is NULL, the subreport is not rendered.

这篇关于列表与LT;对象>作为子报表的JRBeanCollectionDataSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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