Convert Collection/Multiselect input control parameter to string using custom delimiter


I have a multiselect input control that i need to convert to string and then process the values selected. 

I can do this using: $P{Parameter_Name}.toString() . 

This will result in

[ value1,value2,value3,...]

The problem is that some ove the values defined in the input control List of values have ,(comma) in them, which makes it impossible to split the resulted string propperly. What i would like to do is to convert the collection of values to string and be able to specify a diferent delimiter so i can get for example something like [value1|value2|value3|.....]

Is there any way of doing this?

Alex42's picture
Joined: Dec 7 2016 - 4:24am
Last seen: 1 year 8 months ago

3 Answers:


I think you should end all the Input Control Values with a specific character in order to achieve this.

Check this jrxml .

I'm passing 3 input control values

  • This is my First Value^/
  • This is my, Second Value^/
  • This is my Third Value^/

Observe that all my input controls are ending with 2 special characters.

These will be used for checking if the string is ending or not.

In the report, I'm replacing ^/, with a pipe delimiter.

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version using JasperReports Library version 6.2.0  -->
<!-- 2017-04-19T15:21:04 -->
<jasperReport xmlns="" xmlns:xsi="" xsi:schemaLocation="" name="Blank_A4_Landscape_6" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9eb747b4-5176-48bc-acde-ce1f01e95901">
    <parameter name="ArrayList" class="java.util.Collection">
        <defaultValueExpression><![CDATA[java.util.Arrays.asList("This is my First Value^/","This is my, Second Value^/", "This is my Third Value^/")]]></defaultValueExpression>
        <band splitType="Stretch"/>
        <band height="79" splitType="Stretch"/>
        <band height="35" splitType="Stretch"/>
        <band height="61" splitType="Stretch"/>
        <band height="30" splitType="Stretch">
                <reportElement x="0" y="0" width="802" height="30" uuid="79255c56-d765-48e4-91dd-08fd44c9b6bb"/>
                    <font size="11"/>
                <textFieldExpression><![CDATA[$P{ArrayList}.toString().replace("^/,", "|").replace("^/", "").replace("[","").replace("]","")]]></textFieldExpression>
        <band height="45" splitType="Stretch"/>
        <band height="54" splitType="Stretch"/>
        <band height="36" splitType="Stretch"/>

reportdev's picture
Joined: Oct 12 2015 - 12:05pm
Last seen: 8 months 2 weeks ago

Thank you for the solution. It is indeed an option, unfortunately in my case it is the Nuclear Option. Since the input control in question is widely used, adding the custom separator as you suggested(or adding a non printable character as delimiter to not affect the display) would imply making changes in all the queries of all the repoprts that use said input control. There are over 100 reports, at least. 

I am still hoping there is a way to change the delimiter. If not it would be easyer to clean-up the data from the DB

Alex42's picture
Joined: Dec 7 2016 - 4:24am
Last seen: 1 year 8 months ago

You could use a report scriptlet to create a String [value1|value2|value3|.....] parameter based on your input control. For guidance see


shertage's picture
Joined: Sep 26 2006 - 8:06pm
Last seen: 3 months 22 hours ago