Planet Jaspersoft

February 26, 2015

 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. 

February 26, 2015


Planet Jaspersoft aggregates blog posts from our community. If you would like your blog to be included in the Planet, please follow this help guide. Or just click this link to go straight to your Planet Feeds.