Jasper 报告 - 在将参数传递给报告引擎之前进行参数转换?
在将报表参数(输入控件)传递到报表引擎之前,是否可以以任何方式对其进行转换?
我举个例子。我使用 XML 作为数据源:
<Results>
<Object Id="0042" Val="dfg0bb" DateTime="2011-09-30T22:00:04Z" />
<Object Id="0097" Val="abf0cc" DateTime="2011-09-30T22:00:06Z" />
...
</Results>
这是我的 XPath 查询:
//Object[translate(translate(translate(translate(@DateTime, '-', ''), ':', ''), 'T', ''), 'Z', '') <= $P{dateTimeValue}]
字段的描述是:
@Id, @DateTime, @Val
这工作正常,我得到了我想要的,但是日期属性是一个问题,因为我需要将其表示为数量进行比较。可以看出,我需要去掉所有非数字字符,以便将日期作为普通数字进行比较(Java 中 XPath 1.0 的限制)。此外,我想在 JasperServer 中定义此参数的输入控件,并且我希望它是日期类型,以便用户可以从日历中进行选择。
那么,有没有什么方法(scriptlet 或其他东西)可以在将提供的参数传递给报表引擎之前对其进行转换? (在本例中日期为数值,以便 XPath 可以工作)
Is it possible in any way to transform report parameter (input control) before it is passed to report engine?
I'll give an example. I'm using XML as data source:
<Results>
<Object Id="0042" Val="dfg0bb" DateTime="2011-09-30T22:00:04Z" />
<Object Id="0097" Val="abf0cc" DateTime="2011-09-30T22:00:06Z" />
...
</Results>
This is my XPath query:
//Object[translate(translate(translate(translate(@DateTime, '-', ''), ':', ''), 'T', ''), 'Z', '') <= $P{dateTimeValue}]
Descriptions for the fields are:
@Id, @DateTime, @Val
This is working OK, I get what I want, but the date attribute is kind of a problem, because I need to represent it as a number for comparison. As it can be seen I need to strip all non-numerical characters in order to compare dates as plain numbers (limitation of XPath 1.0 in Java). Furthermore, I want to define in JasperServer an input control for this parameter, and I want it to be date type, so user can choose from calendar.
So, is there any way (scriptlet or something) to transform supplied parameter before it is passed to report engine? (In this case date to numerical value so the XPath can work)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用的想法是一个参数可以具有基于另一个参数的默认值。提示用户输入“MyDate”,然后将其转换为“StringBasedOnMyDate”以在 XPath 查询中使用。它在 .jrxml 中看起来像这样:
The idea you need to use is that one parameter can have a default value based on another parameter. Prompt your user for "MyDate" then convert this to "StringBasedOnMyDate" for use in the XPath query. It will look something like this in the .jrxml: