Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table component shows blank report for XML data source

I am facing issues while creating table component in report summary panel using XML as data source, the final report shows a mere blank line .

Below is my xml data source named ProjectXML.xml

<testsuites>
    <testsuite name="testsuite1"/>
    <testsuite name="testsuite2"/>
    <testsuite name="testsuite3"/>
</testsuites>

Below is my .jrxml file named report12.jrxml

<?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="report12" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="bb749013-793e-4a97-a43a-08d89a11ce20">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <style name="table">
        <box>
            <pen lineWidth="1.0" lineColor="#3300CC"/>
        </box>
    </style>
    <style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#3300CC"/>
        </box>
    </style>
    <style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#3300CC"/>
        </box>
    </style>
    <style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#3300CC"/>
        </box>
        <conditionalStyle>
            <conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
            <style backcolor="#EFF7FF"/>
        </conditionalStyle>
    </style>
    <subDataset name="tableDataSet" uuid="44f57638-9650-43f7-9a45-b12c6144c112">
        <queryString language="xPath">
            <![CDATA[/testsuites/testsuite]]>
        </queryString>
        <field name="name" class="java.lang.String">
            <fieldDescription><![CDATA[@name]]></fieldDescription>
        </field>
    </subDataset>
    <queryString language="xPath">
        <![CDATA[/testsuites/testsuite]]>
    </queryString>
    <field name="name" class="java.lang.String">
        <fieldDescription><![CDATA[@name]]></fieldDescription>
    </field>
    <summary>
        <band height="238" splitType="Stretch">
            <componentElement>
                <reportElement uuid="59f049a5-d77e-480c-a1ee-46987630290d" key="table" style="table" x="0" y="0" width="555" height="238"/>
                <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="tableDataSet" uuid="6d3ecced-ba97-49c1-aec9-7f5903748fa5">
                        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    </datasetRun>
                    <jr:column uuid="ed4b1e17-dcec-4ed6-9f1f-efb543f240b7" width="90">
                        <jr:columnHeader style="table_CH" height="30">
                            <staticText>
                                <reportElement uuid="e2772a76-f9da-4438-8aa3-78cee739bdaf" x="0" y="0" width="90" height="30"/>
                                <textElement/>
                                <text><![CDATA[name]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table_TD" height="20">
                            <textField>
                                <reportElement uuid="d496fc00-bab8-4b85-bb8d-c75c1cfc3dc4" x="0" y="0" width="90" height="20"/>
                                <textElement/>
                                <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </summary>
</jasperReport>

Below is the screen shot of the blank preview of the report12.jrxml

report12 Preview

Advanced thanks for any help on this to get the full table with TestSuite names .

like image 692
Som Avatar asked Nov 23 '12 12:11

Som


2 Answers

I've found a "hack" and not very nice method, but it is working.

You can add the main (report's) dataset and use it in the Table component.

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport .. whenNoDataType="AllSectionsNoDetail" ..>
    <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="tbDS">
        <queryString language="xPath">
            <![CDATA[/testsuites/testsuite]]>
        </queryString>
        <field name="name" class="java.lang.String">
            <fieldDescription><![CDATA[@name]]></fieldDescription>
        </field>
    </subDataset>
    <queryString language="xPath">
        <![CDATA[/testsuites/testsuite]]>
    </queryString>
    <field name="name" class="java.lang.String">
        <fieldDescription><![CDATA[@name]]></fieldDescription>
    </field>
    <summary>
        <band height="98" splitType="Stretch">
            <componentElement>
                <reportElement key="table" style="table" x="76" y="33" width="360" height="50"/>
                <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="tbDS">
                        <dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).dataSource("/testsuites/testsuite")]]></dataSourceExpression>
                    </datasetRun>
                    <jr:column width="90">
                        <jr:columnHeader style="table_CH" height="30">
                            <staticText>
                                <reportElement x="0" y="0" width="90" height="30"/>
                                <textElement/>
                                <text><![CDATA[name]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table_TD" height="20">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="20"/>
                                <textElement/>
                                <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </summary>
</jasperReport>

In this sample I've used ((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).dataSource("/testsuites/testsuite") expression for setting Table's datasource.

The result will be:

The resulted report via iReport preview


The another way to get design you want - is to use the Detail band (without using Table component).


I think the situation you described detects the bug of a JasperReports engine.

I've found similar posts at http://community.jaspersoft.com site: Table component and XML datasource and using table elements with xml datasource

like image 123
Alex K Avatar answered Nov 15 '22 14:11

Alex K


I found a solution on IReport, select Edit table Datasource, on dropdown list over Connection / Datasource Expression select

Use datasource Expresion

new net.sf.jasperreports.engine.JREmptyDataSource(1)

and it works from Java app

like image 36
Hache Avatar answered Nov 15 '22 15:11

Hache