Thursday 26 February 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
USA,INDIA,Canada,England

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. 

No comments:

Post a Comment