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:


    <Object Id="0042" Val="dfg0bb" DateTime="2011-09-30T22:00:04Z" />
    <Object Id="0097" Val="abf0cc" DateTime="2011-09-30T22:00:06Z" />

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.

這工作正常,我得到我想要的,但日期屬性是一個問題,因為我需要將其表示為一個數字進行比較。可以看出,我需要刪除所有非數字字符,以便將日期作為普通數字進行比較(Java中XPath 1.0的限制)。此外,我想在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)

那么,在將提供的參數傳遞給報表引擎之前,是否有任何方法(scriptlet或其他)來轉換它? (在這種情況下,日期為數值,以便XPath可以工作)

1 个解决方案



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:


<parameter name="MyDate" class="java.util.Date" isForPrompting="true">
<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>



粤ICP备14056181号  © 2014-2021 ITdaan.com