如何将表的DataSource中的值返回到iReport中的主报表? [英] How to return value from table's DataSource to main report in iReport?
问题描述
我的iReport中有一个表,它自然有它的数据集,我有一个变量,在表的数据集中定义和初始化返回一个值(绝对在表的范围内,不在它的外面)我想要的在我的主报告中使用该表。
I have a table in my iReport which naturally has its dataset and I have a variable, that is defined and initialized in the table's dataset return a value (which definitely does within scope of table, not outside it) which I want to use in my main report which holds the table.
我该怎么做或其他选择?
How can I do that or any alternatives?
推荐答案
如果你想从表数据集中获取一些数据,你实际上可以做到这一点。我找到了一个肮脏的技巧来实现这一点。
If you want to get some data from the table dataset, you actually can do this. I found a dirty trick to achieve this.
-
创建VARIABLE
variableMapName
在主报表中键入java.util.Map
并使用表达式new java.util.HashMap()
Create VARIABLE
variableMapName
of typejava.util.Map
in main report and initialize it with expressionnew java.util.HashMap()
创建类型为 java.util.Map $ c的PARAMETER
parameterMapName
$ c>在表格数据集中
Create PARAMETER parameterMapName
of type java.util.Map
within table dataset
使用编辑表格数据源 - >参数 - >添加 - > $ P链接数据集PARAMETER与主报表中的变量{parameterMapName} = $ V {variableMapName}(右键单击主报告模板中的表格)
Link dataset PARAMETER with variable from main report using "Edit table datasource -> Parameters -> Add -> $P{parameterMapName} = $V{variableMapName}" (right click on the table in main report template)
创建变量 java.lang.String
的> putResult 。此变量的表达式将如下所示
Create variable putResult
of type java.lang.String
in table datasource. Expression for this variable will looks like this
$ P {parameterMapName} .put( KEY,$ F {fieldYouWantReturn})+ $ P {parameterMapName} .put(KEY2,$ F {otherFieldYouWantReturn})
现在,您可以使用 $ V {variableMapName} .get(KEY)
这真的是一个肮脏的黑客,但有时你没有其他办法做某事。
谢谢!
It is really a dirty hack, but sometimes you have no other way to do something. Thanks!
这篇关于如何将表的DataSource中的值返回到iReport中的主报表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!