How to restrict Multiselect input control values in Jaspersoft
This blog will teach the reader , how to restrict multiselect input control values in jasper without hampering the performance .
Make data easy with Helical Insight.
Helical Insight is the world’s best open source business intelligence tool.
DB : Postgres (foodmart)
Table : customer
Reporting tool : iReport
Server : Jasperserver 5.6
I/P Parameter : country
Requirement : Get All the informations from customer table where country name is either USA or Mexico or Canada
Condition :
- you can not select more than 2 value in “country” input parameter
- if more than 2 values are selected in “country” input parameter then the main report query should also not get executed. This will unnecessarily hamper the performance.
Solution :
- create multiselect input control named as “country”
select distinct country from customer
- create a sub report which will display all the informations from customer table on selection of “country” parameter
and give its print when expression as :
$P{country}.size() <= 2
- create a text box in the header , write a message init as :
“You can not select more than 2 values in country parameter”
And give its print when expression as :
$P{country}.size() > 2
- in the sub report , query will be :
select * from customer
where $X{IN,country,country}
limit 20
- publish the report on jasper server.
O/P
# 1 : when 2 values selected in country parameter
#2 : when more than 2 values selected in country parameter
Thanks,
Rupam Bhardwaj
Best Open Source Business Intelligence Software Helical Insight is Here
Hi,
Can you please tell me where to put “$P{country}.size() <= 2" condition
Hi Tapan,
Go to the subreport Properties section . There you will get one Property called “Print when expression” . Here You have to put “$P{country}.size() <= 2".
For your reference I have attached screenshot below :
you need to put that condition on sub report’s “print when expression”.