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. 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 个解决方案

#1


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:

您需要使用的想法是一個參數可以具有基於另一個參數的默認值。提示您的用戶輸入“MyDate”,然后將其轉換為“StringBasedOnMyDate”以在XPath查詢中使用。在.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>

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2011/11/16/72535ab688055dc23bc96f9b83a8e81b.html



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