1

I am facing the problem on how to create array in Jasper, I added new variable which should contain array. But i really do not know how to set this as array.

Thilina Rubasingha
  • 931
  • 1
  • 9
  • 16
Lymuel
  • 564
  • 2
  • 10

1 Answers1

2

It is quite easy.

The report's template

<?xml version="1.0" encoding="UTF-8"?>
<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="array" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="67f7b35d-37a4-4514-9416-5496bb44561f">
    <variable name="arrVar" class="java.lang.String[]">
        <initialValueExpression><![CDATA[new String[]{"Paris", "London", "Berlin"}]]></initialValueExpression>
    </variable>
    <title>
        <band height="50">
            <textField>
                <reportElement x="110" y="10" width="100" height="20" uuid="ea41f111-1bcf-43a0-a98e-7487906133b8"/>
                <textFieldExpression><![CDATA[Arrays.toString($V{arrVar})]]></textFieldExpression>
            </textField>
        </band>
    </title>
</jasperReport>

The result in iReport will be

enter image description here

Note

1) Don't forget to set Java as language for report

2) For more details about how to declare arrays in Java you can look at Declare array (Java) post

Community
  • 1
  • 1
Alex K
  • 21,162
  • 18
  • 101
  • 217