IReport 4.1.3 table component never shows the first entry of the dataset

ireportjasper-reportsxmltable

I have a probably simple problem when using ireport table component. I'm using XML as the datasource for the report.

The problem is that the table never shows the first entry of the dataset associated with it.
Imagine I have this data:

<name>
   <first>adam 1</first>
   <last>sand 1</last>          
</name> 
<name>
   <first>adam 2</first>
   <last>sand 2</last>          
</name> 
<name>
   <first>adam 3</first>
   <last>sand 3</last>          
</name> 

The output (table) will be (all data except the first row):

first last
adam 2 sand 2
adam 3 sand 3

The report 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="consumption_in_zones_data" pageWidth="500" pageHeight="802" columnWidth="500" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <property name="ireport.layers" value="##Tue Dec 06 12:01:43 GMT 2011\nlayer.0.name=Background\nlayer.0.visible=true\nlayer.0.id=0"/>
    <style name="table">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_CH" mode="Opaque" backcolor="#999999">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TD" mode="Opaque" backcolor="#FFFFCC">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 1">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 1_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 1_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 1_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <subDataset name="table dataset">
        <parameter name="ZoneID" class="java.lang.String"/>
        <parameter name="PERIOD" class="java.lang.String"/>
        <parameter name="UNIT" class="java.lang.String"/>
        <queryString language="xPath">
            <![CDATA[/OrganizationData/Building/Zone/Indicator/ActiveEnergy[ZoneID='$P{ZoneID}']]]>
        </queryString>
        <field name="time" class="java.lang.String">
            <fieldDescription><![CDATA[time]]></fieldDescription>
        </field>
        <field name="consumption" class="java.lang.Double">
            <fieldDescription><![CDATA[consumption]]></fieldDescription>
        </field>
    </subDataset>
    <parameter name="ZoneID" class="java.lang.String"/>
    <parameter name="PERIOD" class="java.lang.String"/>
    <parameter name="UNIT" class="java.lang.String"/>
    <queryString language="xPath">
        <![CDATA[/OrganizationData/Building/Zone/Indicator/ActiveEnergy[ZoneID='$P{ZoneID}']]]>
    </queryString>
    <field name="time" class="java.lang.String">
        <fieldDescription><![CDATA[time]]></fieldDescription>
    </field>
    <field name="consumption" class="java.lang.Double">
        <fieldDescription><![CDATA[consumption]]></fieldDescription>
    </field>
    <variable name="consumption_1" class="java.lang.Double" resetType="Column" calculation="Sum">
        <variableExpression><![CDATA[$F{consumption}]]></variableExpression>
    </variable>
    <variable name="consumption_2" class="java.lang.Double" resetType="Column" calculation="Sum">
        <variableExpression><![CDATA[$F{consumption}]]></variableExpression>
    </variable>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="197" splitType="Stretch">
            <componentElement>
                <reportElement key="table 1" style="table 1" x="0" y="0" width="500" height="197"/>
                <jr:table 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="table dataset">
                        <datasetParameter name="ZoneID">
                            <datasetParameterExpression><![CDATA[$P{ZoneID}]]></datasetParameterExpression>
                        </datasetParameter>
                        <datasetParameter name="PERIOD">
                            <datasetParameterExpression><![CDATA[$P{PERIOD}]]></datasetParameterExpression>
                        </datasetParameter>
                        <datasetParameter name="UNIT">
                            <datasetParameterExpression><![CDATA[$P{UNIT}]]></datasetParameterExpression>
                        </datasetParameter>
                        <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
                    </datasetRun>
                    <jr:column width="90">
                        <jr:tableHeader style="table 1_TH" height="30" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="30"/>
                                <textElement textAlignment="Center"/>
                                <textFieldExpression><![CDATA[$P{PERIOD}]]></textFieldExpression>
                            </textField>
                        </jr:tableHeader>
                        <jr:detailCell style="table 1_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="20"/>
                                <textElement textAlignment="Center"/>
                                <textFieldExpression><![CDATA[$F{time}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90">
                        <jr:tableHeader style="table 1_TH" height="30" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="30"/>
                                <textElement textAlignment="Center"/>
                                <textFieldExpression><![CDATA[$P{UNIT}]]></textFieldExpression>
                            </textField>
                        </jr:tableHeader>
                        <jr:detailCell style="table 1_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="20"/>
                                <textElement textAlignment="Center"/>
                                <textFieldExpression><![CDATA[$F{consumption}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </detail>
</jasperReport>

Data snippet:

<OrganizationData>
  <Building>
    <BuildingID>71721890-efd1-012c-c545-0a48cbee2b22</BuildingID>
    <BuildingName>PT</BuildingName>
    <Tariff>low</Tariff>
    <Zone>
      <ZoneID>bceba570-d0e2-012e-d950-7ac0bc5389eb</ZoneID>
      <BuildingID>71721890-efd1-012c-c545-0a48cbee2b22</BuildingID>
      <ZoneName>PT - Zone A</ZoneName>
      <Type>ROUT</Type>
      <Indicator>
        <IndicatorID>96a41e20-60d8-012d-516c-5aacf9dbb012</IndicatorID>
        <ZoneID>bceba570-d0e2-012e-d950-7ac0bc5389eb</ZoneID>
        <BuildingID>71721890-efd1-012c-c545-0a48cbee2b22</BuildingID>
        <IndicatorName>EA+ BlA P0</IndicatorName>
        <ActiveEnergy>
          <IndicatorID>96a41e20-60d8-012d-516c-5aacf9dbb012</IndicatorID>
          <ZoneID>bceba570-d0e2-012e-d950-7ac0bc5389eb</ZoneID>
          <BuildingID>71721890-efd1-012c-c545-0a48cbee2b22</BuildingID>
          <time>01 Oct</time>
          <consumption>0.1</consumption>
        </ActiveEnergy>
        <ActiveEnergy>
          <IndicatorID>96a41e20-60d8-012d-516c-5aacf9dbb012</IndicatorID>
          <ZoneID>bceba570-d0e2-012e-d950-7ac0bc5389eb</ZoneID>
          <BuildingID>71721890-efd1-012c-c545-0a48cbee2b22</BuildingID>
          <time>02 Oct</time>
          <consumption>0.1</consumption>
        </ActiveEnergy>
      </Indicator>
    </Zone>
  </Building>
</OrganizationData>

thanks in advance,
Nuno

Best Answer

I've just check the table element with this test case.

My template:

<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="tablesample2" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <style name="table">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <subDataset name="Table Dataset 1">
        <field name="city" class="java.lang.String"/>
        <field name="id" class="java.lang.String"/>
    </subDataset>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="city" class="java.lang.String"/>
    <field name="id" class="java.lang.String"/>
    <detail>
        <band height="80" splitType="Stretch">
            <componentElement>
                <reportElement key="table" style="table" x="100" y="0" width="270" height="80"/>
                <jr:table 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="Table Dataset 1">
                        <dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
                    </datasetRun>
                    <jr:column width="90">
                        <jr:detailCell style="table_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="20"/>
                                <textElement/>
                                <textFieldExpression><![CDATA[$F{city}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90">
                        <jr:detailCell style="table_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="20"/>
                                <textElement/>
                                <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90">
                        <jr:detailCell style="table_TD" height="20" rowSpan="1"/>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </detail>
</jasperReport>

My csv data file was:

"Dallas",47,"Janet Fuller","445 Upland Pl.","Trial"
"Lyon",38,"Andrew Heiniger","347 College Av.","Active"
"Dallas",43,"Susanne Smith","2 Upland Pl.","Active"
"Berne",22,"Bill Ott","250 - 20th Ave.","Active"
"Boston",32,"Michael Ott","339 College Av.","Trial"
"Dallas",4,"Sylvia Ringer","365 College Av.","Active"
"Boston",23,"Julia Heiniger","358 College Av.","Active"
"Chicago",39,"Mary Karsen","202 College Av.","Active"
"Dallas",40,"Susanne Miller","440 - 20th Ave.","Trial"
"Berne",9,"James Schneider","277 Seventh Av.","Active"
"Dallas",36,"John Steel","276 Upland Pl.","Suspended"
"Chicago",35,"George Karsen","412 College Av.","Suspended"
"Dallas",37,"Michael Clancy","19 Seventh Av.","Deleted"
"Lyon",2,"Anne Miller","20 Upland Pl.","Active"
"Dallas",0,"Laura Steel","429 Seventh Av.","Active"
"Lyon",28,"Susanne White","74 - 20th Ave.","Deleted"
"Paris",5,"Laura Miller","294 Seventh Av.","Active"
"Lyon",17,"Laura Ott","443 Seventh Av.","Active"
"New York",46,"Andrew May","172 Seventh Av.","Active"
"New York",44,"Sylvia Ott","361 College Av.","Active"
"Dallas",19,"Susanne Heiniger","86 - 20th Ave.","Active"
"Chicago",11,"Julia White","412 Upland Pl.","Active"
"Dallas",10,"Anne Fuller","135 Upland Pl.","Active"
"New York",41,"Bill King","546 College Av.","Deleted"
"Oslo",45,"Janet May","396 Seventh Av.","Active"
"Paris",18,"Sylvia Fuller","158 - 20th Ave.","Trial"
"San Francisco",48,"Robert White","549 Seventh Av.","Active"
"Paris",25,"Sylvia Steel","269 College Av.","Suspended"
"San Francisco",7,"James Peterson","231 Upland Pl.","Active"
"Oslo",42,"Robert Ott","503 Seventh Av.","Trial"

The first row from the data source was missed in the table.

I think this is issue related with iteration over the main datasource. You can read
Why is the first record missing from my subreport?
post on community.jaspersoft.com.

Related Topic