DynamicJasper:访问串联报告中动态列的值
我需要在 DynamicJasper 中创建一个报告,其中包含多个包含不同列的“子报告”。列的数据存储在每行对象的 HashMap 中。我在 DynamicJasper 中没有找到任何方法来指定列的值应来自 HashMap 上的特定键。
我发现,如果我构建一个报告,我可以扩展 JRAbstractBeanDataSource 并创建我自己的数据源,该数据源知道如何根据我格式化字段名称的方式正确获取数据。但是,当我使用 addConcatenatedReport 添加多个报告时,“子报告”使用 JRBeanCollectionDataSource 而不是我的自定义数据源。
到目前为止,我提出的唯一解决方案是拥有一个 POJO,它具有一堆属性,例如“column1value”和“column2value”,我预加载这些属性并将其用于动态列中的字段引用。我真的不想这样做...有人能想到其他选择吗?我缺少什么吗?
旁注:您知道为什么不能将自定义数据源类型传递给 addConcatenatedReport 函数吗?技术问题,还是根本不需要?看起来这将是对“动态”报告的常见需求。
I have a need to create a report in DynamicJasper that has multiple "subreports" which contain different columns. The data for the columns is stored in a HashMap on each row Object. I have not found any way in DynamicJasper to specify that a column's value should come from a particular key on the HashMap.
I have found that if I build a single report, I can extend JRAbstractBeanDataSource and create my own Data Source that knows how to get the data correctly based on how I format the field name. However, when I use addConcatenatedReport to add in multiple reports, the "subreports" use JRBeanCollectionDataSource instead of my custom Data Source.
The only solution I have come up with so far is to have a POJO that has a bunch of properties like "column1value" and "column2value" which I preload and use for the field references in the dynamic columns. I really don't want to do this...can anyone think of any other options? Anything I am missing?
Sidenote: any ideas why you can't pass a custom data source type to the addConcatenatedReport function? Technical issues, or it just hasn't been needed? Seems like this would be a common need for a "dynamic" report.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
昨天我正在寻找同样的东西,我发现了你的帖子(我看到它是最近的)。经过一番搜索后,我设法克服了这个问题,所以我想与大家分享我的发现会很高兴。
我想您为数据定义了一个 POJO,然后将所有这些对象添加到 HashMap(如果我是对的,请纠正我)。
我所做的是创建一个扩展 HashMap 实现的新对象。 (事实上你不必扩展它,你可以使用 HashMap 对象本身)。因此,现在我不再将对象放在 HashMap 中,而是直接插入属性值。但是,让我们只添加一些代码块来清除事情:)
假设您有以下 PoJO,
您可以使用 HashMap 这种方式来定义对象,而不是将这些不同的对象添加到 List 并将其作为数据源提供:
定义这些对象之后我们可以将对象添加到列表中并将其作为数据源提供(
JRBeanCollectionDataSource
)。因此每个HashMap
的键被认为是Columns中定义的属性(初始POJO的属性)。我不知道我的解决方案是否是最好的,但它对我有用!
I was searching for the same thing yesterday and I came across your post (and I saw it was recent). After some search I managed to overcome this problem so I thought it would be nice to share with you my findings.
I suppose that you defined an POJO for your data and then added all these objects to the HashMap (correct me if I am right).
What I did was to create a new Object that extends HashMap implementation. (In fact you dont have to extend this, you can use the HashMap object itself). So now instead of having objects inside HashMap I directly inserted values for the properties. But lets just add some code blocks in order to clear things :)
Suppose that you have the following PoJO
Instead of adding these various objects to a List and providing it as datasource you can use a HashMap this way to define your objects:
After defining these objects we can add them in a List and provide it as datasource (
JRBeanCollectionDataSource
). So the keys of eachHashMap
are considered to be the properties defined in the Columns (the properties of the initial POJO).I dont know if my solution is the best but it worked for me!