Alex42 Posted April 19, 2017 Share Posted April 19, 2017 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? Link to comment Share on other sites More sharing options...
reportdev Posted April 19, 2017 Share Posted April 19, 2017 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 valuesThis 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 6.2.0.final using JasperReports Library version 6.2.0 --><!-- 2017-04-19T15:21:04 --><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" 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> </parameter> <queryString> <![CDATA[]]> </queryString> <background> <band splitType="Stretch"/> </background> <title> <band height="79" splitType="Stretch"/> </title> <pageHeader> <band height="35" splitType="Stretch"/> </pageHeader> <columnHeader> <band height="61" splitType="Stretch"/> </columnHeader> <detail> <band height="30" splitType="Stretch"> <textField> <reportElement x="0" y="0" width="802" height="30" uuid="79255c56-d765-48e4-91dd-08fd44c9b6bb"/> <textElement> <font size="11"/> </textElement> <textFieldExpression><![CDATA[$P{ArrayList}.toString().replace("^/,", "|").replace("^/", "").replace("[","").replace("]","")]]></textFieldExpression> </textField> </band> </detail> <columnFooter> <band height="45" splitType="Stretch"/> </columnFooter> <pageFooter> <band height="54" splitType="Stretch"/> </pageFooter> <summary> <band height="36" splitType="Stretch"/> </summary></jasperReport>[/code] Link to comment Share on other sites More sharing options...
Alex42 Posted April 20, 2017 Author Share Posted April 20, 2017 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 Link to comment Share on other sites More sharing options...
szaharia Posted April 20, 2017 Share Posted April 20, 2017 You could use a report scriptlet to create a String [value1|value2|value3|.....] parameter based on your input control. For guidance seehttp://community.jaspersoft.com/wiki/jasperreports-library-tutorial#Scriptletsandhttp://jasperreports.sourceforge.net/sample.reference/scriptlet/index.html#scriptlet Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now