Search code examples
jasper-reports

List component displays only the first row


In my JasperReport's report only the first row of my collection gets displayed. Here is the relevant code.

The entity

public class LegendEntity implements Serializable{

    private String label;
    private Image bufferedImage;

    public LegendEntity() {
    }

    public LegendEntity(String label) {
        this.label = label;
    }

    public LegendEntity(String label,Image bufferedImage) {
        this.label = label;
        this.bufferedImage = bufferedImage;
    }

    //getters-setters

Preparing the datasource:

List<MyEntity> myEntitiesList = new ArrayList<>();
//filling the list
JRBeanCollectionDataSource entityDS= new JRBeanCollectionDataSource(myEntitiesList ,false);
report.getReportParameters().put("ENTITY_DATASOURCE", entityDS);

The jrxml:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ... name="SampleReport" printOrder="Horizontal" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
    <subDataset name="LegendDataset" uuid="e0d72aca-6fd5-4935-b57f-ff5a436f2afb">
        <field name="label" class="java.lang.String">
            <fieldDescription><![CDATA[]]></fieldDescription>
        </field>
        <field name="bufferedImage" class="java.awt.Image"/>
    </subDataset>
    <parameter name="P_MAP_SCALE_STR" class="java.lang.String"/>
    <parameter name="ENTITY_DATASOURCE" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
    <detail>
        <band height="842" splitType="Stretch">
            <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/>
            <frame>
                <reportElement x="298" y="635" width="298" height="206" uuid="e807b35a-857c-43ba-a080-13f422eb1456"/>
                <componentElement>
                    <reportElement x="11" y="11" width="275" height="186" uuid="d6f579d3-75de-4745-8f94-c974d2e697a0"/>
                    <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" printOrder="Vertical">
                        <datasetRun subDataset="LegendDataset" uuid="ee194811-e7e5-4102-83ff-b150901d73c9">
                            <dataSourceExpression><![CDATA[$P{ENTITY_DATASOURCE}]]></dataSourceExpression>
                        </datasetRun>
                        <jr:listContents height="186" width="275">
                            <staticText>
                                <reportElement x="10" y="10" width="130" height="20" uuid="4260f10d-ee62-4cf6-8023-d0dc2266f4dd"/>
                                <textElement textAlignment="Center"/>
                                <text><![CDATA[ENTITY LABEL]]></text>
                            </staticText>
                            <staticText>
                                <reportElement x="150" y="10" width="100" height="20" uuid="88135c50-3c17-4b0f-b7e5-b05987f98b02"/>
                                <textElement textAlignment="Center"/>
                                <text><![CDATA[ENTITY SYMBOL]]></text>
                            </staticText>
                            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                                <reportElement x="10" y="31" width="130" height="18" uuid="30885d06-38db-4b1c-a312-616a60ee1c42"/>
                                <textFieldExpression><![CDATA[$F{label}]]></textFieldExpression>
                            </textField>
                            <image>
                                <reportElement x="150" y="31" width="100" height="18" uuid="0020adca-acad-4915-9f0d-88d75e4897c7"/>
                                <imageExpression><![CDATA[$F{bufferedImage}]]></imageExpression>
                            </image>
                        </jr:listContents>
                    </jr:list>
                </componentElement>
            </frame>
            <staticText>
                <reportElement x="30" y="600" width="80" height="18" uuid="6c1afd65-a8d4-4e3f-9a56-d09abe7ec904"/>
                <textElement textAlignment="Right">
                    <font fontName="DejaVu Sans" size="9" isBold="true"/>
                </textElement>
                <text><![CDATA[Ölçek: 1/]]></text>
            </staticText>
            <textField>
                <reportElement positionType="Float" x="110" y="600" width="100" height="18" uuid="6360a545-63af-48cc-987d-d828c24a3b2a"/>
                <textElement>
                    <font fontName="DejaVu Sans" size="9" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{P_MAP_SCALE_STR}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

And on the report only the first entity's label and symbol is displayed. What am I missing?

Debugging already done and I am sure that 1+ entities are present in the list.

The whole JRXML here .


Solution

  • I have noticed at least 2 problems in your main JRXML:

    1. Setting printOrder="Horizontal" at the report level may prevent proper elements overflow. Try reverting to printOrder="Vertical" or remove the attribute completely.
    2. There is too much whitespace inside the list element that would force overflow. You should not have white space after the last elements.