How print a array in jasper ?

0

Hi, I need help, I am sending the parameter in array, to printed in the report the problem is:

It is printed like this:
"[ex]"

And I need to print like this, like a table:

ex1
-----
ex2

I don't use a query to send the parameters, I sending for a array using a framework in php, is just a test to implement in a real report, I just need know how I can do that, someone can help ?

gabriel.nadoroski's picture
Joined: Oct 1 2018 - 2:05pm
Last seen: 11 months 2 weeks ago

Thanks reportdev!

You saved me, I giving up doing of make the report in jaspersoft

But you saved me, your answer helped me.

gabriel.nadoroski - 1 year 1 month ago

3 Answers:

1

you need to convert the List to JRBeanCollectionDataSource in order for it to iterate and use a List element

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.4.2.final using JasperReports Library version 6.4.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="Iterator" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="20f55d6a-1496-430d-8dde-cdb41d7b53ac">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <subDataset name="Dataset1" uuid="a32a36ba-2e14-4071-9649-c5738d43e63a">
        <queryString>
            <![CDATA[]]>
        </queryString>
        <field name="_THIS" class="java.lang.String"/>
    </subDataset>
    <parameter name="arrayAccepter" class="java.util.List">
        <defaultValueExpression><![CDATA[Arrays.asList("Hello1", "Hello2", "Hello3", "Hello4")]]></defaultValueExpression>
    </parameter>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="90">
            <textField>
                <reportElement x="0" y="0" width="290" height="30" uuid="5208b9c8-6128-4f52-90de-7d93bbd0294e"/>
                <textFieldExpression><![CDATA[$P{arrayAccepter}.toString()]]></textFieldExpression>
            </textField>
            <componentElement>
                <reportElement x="0" y="60" width="100" height="30" uuid="b014b59d-186c-42cd-b975-a7a1ca18ca9f"/>
                <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                    <datasetRun subDataset="Dataset1" uuid="b3c55d8f-90d9-4ddc-9fa1-66da2cb48783">
                        <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{arrayAccepter})]]></dataSourceExpression>
                    </datasetRun>
                    <jr:listContents height="30" width="100">
                        <textField>
                            <reportElement x="0" y="0" width="100" height="30" uuid="c6bd4e2a-e756-4089-bdf7-9b06b5575201"/>
                            <textFieldExpression><![CDATA[$F{_THIS}]]></textFieldExpression>
                        </textField>
                    </jr:listContents>
                </jr:list>
            </componentElement>
        </band>
    </detail>
</jasperReport>

reportdev's picture
1222
Joined: Oct 12 2015 - 12:05pm
Last seen: 37 min 53 sec ago
1

If your need is to remove square brackets I think below should be of help

https://community.jaspersoft.com/blog/tip-remove-and-collection-paramete...

sadakar's picture
627
Joined: Aug 14 2012 - 3:57am
Last seen: 2 weeks 1 day ago
0

Thanks !

This helpful, but I need broke him in lines, like a table in execl.
Let's see, I think this can help you understand my problem.

I am doing a query in PHP in the database, that query brings to me a quantity of payments and the date of this payments, and I need to make a table with that data in xls.

gabriel.nadoroski's picture
Joined: Oct 1 2018 - 2:05pm
Last seen: 11 months 2 weeks ago
Feedback
randomness