sneha.sinha_1 Posted June 14, 2019 Share Posted June 14, 2019 Suppose I have got a dataset from query as-ColumnAColumnBColumnC ColumnDA1B1C1D11,D21,D31A2B2C2D21,D22,D32 I am trying to split it like following-ColumnAColumnBColumnCColumnDA1B1C1D11A1B1C1D21A1B1C1D31A2B2C2D21A2B2C2D22A2B2C2D32Can anyone suggest anything.I have tried $F{ColumnD}.split(",") but that returns an array of string ,which I dont know how to traverse in Jasper.RThe length of ColumnD is dynamic. Link to comment Share on other sites More sharing options...
Filip C. Posted June 15, 2019 Share Posted June 15, 2019 What database are you using ?Can't you do this in the SQL statement ? Most probably SQL and your database will be faster then JasperSoft and Java (or Groovy). Link to comment Share on other sites More sharing options...
C-Box Posted June 19, 2019 Share Posted June 19, 2019 You could 1. create an Array of Strings based on your Field:$F{ColumnD}.split(",") [/code]and 2. create an ArrayList of that:Arrays.asList($F{ColumnD}.split(",") [/code]and 3. use this list for an ListElement or even a SubReport as a JRBeanCollectionDataSource using finally this as DataSourceExpression:new JRBeanCollectionDataSource(Arrays.asList($F{ColumnD}.split(",") ))[/code]in your List or SubReport you must create a Field named "_THIS" of type String that you can place within the Listelement or the detail of your SubReport.just tried it out with following parameter in a new empty (main) record:<parameter name="MyStrings" class="java.util.List" nestedType="java.lang.String" isForPrompting="false"> <defaultValueExpression><![CDATA[Arrays.asList("Record1", "2. Record","and the third one")]]></defaultValueExpression> </parameter>[/code]and this for SubReport expression:<subreport> <reportElement x="0" y="10" width="545" height="60" uuid="7f7e06fb-1788-4fdc-a1a3-3f5dd3745533"/> <dataSourceExpression><![CDATA[new JRBeanCollectionDataSource($P{MyStrings})]]></dataSourceExpression> <subreportExpression><![CDATA["StringListAsDataSource_Sub.jasper"]]></subreportExpression> </subreport>[/code]and this as whole SubReport:<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.5.1 --><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="StringListAsDataSource_Sub" pageWidth="595" pageHeight="842" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="9d9ea5fd-fadc-4890-827f-369ee64374e3"> <property name="com.jaspersoft.studio.unit." value="pixel"/> <property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/> <property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/> <property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/> <property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/> <queryString> <![CDATA[]]> </queryString> <field name="_THIS" class="java.lang.String"/> <background> <band splitType="Stretch"/> </background> <detail> <band height="30" splitType="Stretch"> <textField> <reportElement x="0" y="0" width="440" height="30" uuid="2beea897-e04d-4bc2-aa50-1238ad9aef85"> <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="837e5d94-d9e1-4f14-af77-3dc9369ce311"/> </reportElement> <textFieldExpression><![CDATA[$F{_THIS}]]></textFieldExpression> </textField> </band> </detail></jasperReport>[/code] hth + regardsC-Box 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