简体   繁体   English

Jasper报告-将参数传递到报告引擎之前进行参数转换?

[英]Jasper reports - parameter transformation before passing it to report engine?

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: 我使用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>

This is my XPath query: 这是我的XPath查询:

//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. 这样就可以了,我可以得到想要的,但是date属性有点问题,因为我需要将它表示为一个数字以进行比较。 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). 可以看出,为了将日期与纯数字进行比较,我需要去除所有非数字字符(Java中XPath 1.0的限制)。 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. 此外,我想在JasperServer中定义此参数的输入控件,并且希望它是日期类型,以便用户可以从日历中选择。

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) (在这种情况下,日期必须为数值,以便XPath可以正常工作)

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. 提示您的用户输入“ MyDate”,然后将其转换为“ StringBasedOnMyDate”以用于XPath查询。 It will look something like this in the .jrxml: 在.jrxml中看起来像这样:

<parameter name="MyDate" class="java.util.Date" isForPrompting="true">
  <defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<parameter name="StringBasedOnMyDate" class="java.lang.String" isForPrompting="false">
  <defaultValueExpression><![CDATA[new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format($P{MyDate})]]></defaultValueExpression>
</parameter>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM