Dataset Expression Filter - filtering using contents of report parameter (type java.util.List)

0

 Folks,

Consider the following scenario. I have a dataset which I'd lile to filter the contents of. The dataset query defines a call to a stored procedure which returns a resultset containing a small number of columns - one of which contains an 'id' value which I wish to filter on. I can already successfully filter the results using something along the lines of:

 

$F{myIdField}.equals(1) || $F{myIdField}.equals(2) || ... and so on.

However, I'd really like to pass in a list of filter ID's as a report parameter and perform the filtering like this:

$P{MY_REPORT_PARAM_LIST}.contains($F{myIdField})

where MY_PARAM_LIST is defined as type java.util.List and contains multiple ID's (in this case Integers) that I want to match on.

But this doesn't seem to work and all records in my dataset are filtered out. As a test, I created a dummy Text Field on the title page of my report and added the following expression:

$P{MY_REPORT_PARAM_LIST}.contains("1")

which successfully returned the  correct results based on input, i.e.:

1,2,3,4 - true

2,3,4,5 - false

So, why does this seem to work as a simple text field expression, but not as a dataset filter expression.

I even tried updating the dataset filter expression to this:

$P{MY_REPORT_PARAM_LIST}.contains("1") and ran the report, passing in a list of 1,2,3 - so I would have expected this to evaluate to true and not filter any results - but everything was filtered as before.

Product Version: Jaspersoft iReport Designer 4.5.1

Java: 1.7.0_02; Java HotSpot(TM) Client VM 22.0-b10

System: Windows 7 version 6.1 running on x86; Cp1252; en_US (ireport)

 

Any ideas?   

 



Post Edited by ballinascreen at 05/29/2012 21:17
ballinascreen's picture
Joined: May 29 2012 - 12:48pm
Last seen: 3 years 2 months ago

3 Answers:

0

A little further testing seems to confirm that the report parameter value is not being passed to the filter expression of the dataset. For example, if I set the filter expression to:

$P{MY_REPORT_PARAM_LIST} == null

all my records are displayed, that is, none are filtered because the MY_REPORT_PARAM_LIST appears to be null

$P(MY_REPORT_PARAM_LIST} != null

all my records are now filtered out

So, why is the value of the report parameter seemingly not made available to dataset filter expressions but can be used elsewhere in the report - or am I missing something fundamental here?

ballinascreen's picture
Joined: May 29 2012 - 12:48pm
Last seen: 3 years 2 months ago
0

 Further update:

Seems like the following works instead:

((ArrayList) $P{REPORT_PARAMETERS_MAP}.get( "MY_REPORT_PARAM_LIST" )).contains($F{myIdField}.toString())

where I extract the list from the built-in report parameter REPORT_PARAMETERS_MAP

Still doesn't explain why the value of my dedicated report parameter is not made available to the dataset filter expression, but I'm happy at least that I can get the filter working another way.

ballinascreen's picture
Joined: May 29 2012 - 12:48pm
Last seen: 3 years 2 months ago
0

Hi,

Thank you very much for this solution. It helped me a lot but struck with a small issue.

If I don't pass any value from input I need to get all the records.

How can I give OR condition combining with above condition ? or How can I get all the values if I dont pass any thing.

sadakar's picture
546
Joined: Aug 14 2012 - 3:57am
Last seen: 1 month 1 day ago
Feedback