Som*_*Som 7 xml jasper-reports
我在使用XML作为数据源在报表摘要面板中创建表组件时遇到问题,最终报表仅显示空白行.
下面是我的名为ProjectXML.xml的 xml数据源
<testsuites>
<testsuite name="testsuite1"/>
<testsuite name="testsuite2"/>
<testsuite name="testsuite3"/>
</testsuites>
Run Code Online (Sandbox Code Playgroud)
下面是我的名为report12.jrxml的.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>
Run Code Online (Sandbox Code Playgroud)
以下是report12.jrxml空白预览的屏幕截图
高级感谢您提供有关TestSuite名称的完整表格的任何帮助.
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>
Run Code Online (Sandbox Code Playgroud)
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 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