Jaspersoft BI Tools

iReport,Jaspersoft Design Studio,Jaspersoft Server, Schema Workbench,Analysis,Dashboards, Self Service BI, Domains,Topics,Ad-Hoc Reports, Jaspersoft ETL, Embedding BI,HTML-5 charts, Fusion Charts,JFree Charts,Drill down reports , Drill down Dashboards,Visualize.js, Performance Tuning, D3 Charts, Jaspersoft Customization

Thursday, February 26, 2015

Tip : Remove [ and ] from collection parameter in jasper reports

 Hi Folks,

This tip will useful for removing square brackets from collection type parameter in jasper reports.

Parameter Type : java.util.Collection
Lets say your input control values are : USA,INDIA,Canada,England in a drop down & when you execute the report
When you display this parameter on the report you will get like this
[ USA,INDIA,Canada,England]

To Convert above to

We need to write below expression for the parameter dragged on to the report (i.e., In its Text Field Expression). 

$P{ParameterName}.toString().substring(1,$P{ParameterName}.toString().length()-1 )

Example :  
$P{Country}.toString().substring(1,$P{Country}.toString().length()-1 )

Notes : 
1) Convert collection to String using toString() function.
2) String index starts from 0 and ends with n-1
3) From the string take the sub string excluding 0th index character and last index character

Thank you Harish for R&D.

NOTE : There could be another ways also to achieve the same.