我目前第一次尝试在JasperReports中使用列表组件,而且我发现了困难。
在JR Studio中,我正确配置了列表并设法在预览中显示它;但是,在Java中使用报表时,我正确地将它JRXmlDataSource
提供给它(因为它在报表中显示数据),但是它没有到达列表组件,它显示0行。
我尝试过但没有工作:
XML_DATA_DOCUMENT
参数(它在JR Studio中是如何工作的,在它之外没有这样的运气),或XML_INPUT_STREAM
一个,或任意数量的XML_
默认参数JRXmlDataSource
存储在参数中并将其作为REPORT_DATA_SOURCE
JRXmlDataSource
- 参数传递为<dataSourceExpression>
Auto
,或检查Print when Overflow
框做了什么工作:
这是.jrxml
文件(简化):
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1 -->
<!-- 2017-02-21T12:03:07 -->
<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="InterventoDipendente" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="96a3ac3a-7d55-40dc-bf6d-11204521d521">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="DataAdapter.xml"/>
<subDataset name="Dataset1" uuid="0852c8da-7fc3-4f80-b57b-43807b503678">
<parameter name="dipId" class="java.lang.Long"/>
<queryString language="xPath">
<![CDATA[/list/intervento]]>
</queryString>
<field name="voceCodice_1" class="java.lang.String">
<fieldDescription><![CDATA[voce/descrizione]]></fieldDescription>
</field>
<field name="durata_1" class="java.lang.Double">
<fieldDescription><![CDATA[durata]]></fieldDescription>
</field>
<field name="dataIntervento_1" class="java.util.Date">
<fieldDescription><![CDATA[dataIntervento]]></fieldDescription>
</field>
<field name="dipendenteId_1" class="java.lang.Long">
<fieldDescription><![CDATA[dipendente/id]]></fieldDescription>
</field>
<sortField name="dataIntervento_1"/>
</subDataset>
<parameter name="XML_DATA_SOURCE" class="net.sf.jasperreports.engine.data.JRXmlDataSource" isForPrompting="false"/>
<queryString language="XPath">
<![CDATA[/list/intervento]]>
</queryString>
<field name="dataIntervento" class="java.util.Date">
<fieldDescription><![CDATA[dataIntervento]]></fieldDescription>
</field>
<field name="dipendenteId" class="java.lang.Long">
<fieldDescription><![CDATA[dipendente/id]]></fieldDescription>
</field>
<field name="dipendenteNome" class="java.lang.String">
<fieldDescription><![CDATA[dipendenteNome]]></fieldDescription>
</field>
<field name="durata" class="java.lang.Double">
<fieldDescription><![CDATA[durata]]></fieldDescription>
</field>
<field name="voceC" class="java.lang.String">
<fieldDescription><![CDATA[voce/codice]]></fieldDescription>
</field>
<sortField name="dipendenteId"/>
<variable name="durata1" class="java.lang.Double" resetType="Group" resetGroup="Dipendente" calculation="Sum">
<variableExpression><![CDATA[$F{durata}]]></variableExpression>
</variable>
<variable name="ass" class="java.lang.Double" resetType="Group" resetGroup="Dipendente" calculation="Sum">
<variableExpression><![CDATA[($F{voceC}.equals("Ass_sist") ? $F{durata} : 0.0)]]></variableExpression>
</variable>
<group name="Dipendente" isStartNewPage="true">
<groupExpression><![CDATA[$F{dipendenteId}]]></groupExpression>
<groupFooter>
<band height="120">
<textField pattern="0.#">
<reportElement x="100" y="60" width="80" height="30" uuid="48f3f8ea-b083-47cf-9a9f-323ad86829a4"/>
<textFieldExpression><![CDATA[$V{durata1}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="30" width="100" height="30" uuid="ca3d0a18-c276-4f1b-8e00-c13a2fea64f7"/>
<textFieldExpression><![CDATA[$F{dipendenteNome}]]></textFieldExpression>
</textField>
<componentElement>
<reportElement key="" positionType="Float" x="180" y="30" width="372" height="30" isPrintWhenDetailOverflows="true" uuid="afdd4606-9306-4c0d-8a94-0ce962b91b8a">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.FreeLayout"/>
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value="List1"/>
</reportElement>
<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="Dataset1" uuid="f805abf9-255f-46d7-b0ca-c9e971c63e78">
<datasetParameter name="dipId">
<datasetParameterExpression><![CDATA[$F{dipendenteId}]]></datasetParameterExpression>
</datasetParameter>
<datasetParameter name="XML_DATE_PATTERN">
<datasetParameterExpression><![CDATA["yyyy-MM-dd'T'HH:mm:ss"]]></datasetParameterExpression>
</datasetParameter>
<datasetParameter name="XML_DATA_DOCUMENT">
<datasetParameterExpression><![CDATA[$P{XML_DATA_DOCUMENT}]]></datasetParameterExpression>
</datasetParameter>
<datasetParameter name="XML_INPUT_STREAM">
<datasetParameterExpression><![CDATA[$P{XML_INPUT_STREAM}]]></datasetParameterExpression>
</datasetParameter>
<datasetParameter name="REPORT_DATA_SOURCE">
<datasetParameterExpression><![CDATA[$P{XML_DATA_SOURCE}]]></datasetParameterExpression>
</datasetParameter>
</datasetRun>
<jr:listContents height="30" width="372">
<textField isStretchWithOverflow="true">
<reportElement x="0" y="0" width="124" height="30" uuid="3e35abd0-d7b2-450d-99af-8ff22943556b"/>
<textFieldExpression><![CDATA[$F{voceCodice_1}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="0.#">
<reportElement x="124" y="0" width="66" height="30" uuid="5c162489-ef8c-4fdc-a586-158952d4fc8b"/>
<textFieldExpression><![CDATA[$F{durata_1}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="dd-MM-yy">
<reportElement x="248" y="0" width="124" height="30" uuid="16e276ff-7506-4e13-bf64-8c64d461dc63"/>
<textFieldExpression><![CDATA[$F{dataIntervento_1}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" evaluationTime="Auto">
<reportElement x="190" y="0" width="58" height="30" uuid="3e110827-40e4-4c51-96f6-d47a685f79e8"/>
<textFieldExpression><![CDATA["s"]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
<textField pattern="MMMMM yyyy">
<reportElement x="0" y="0" width="100" height="30" uuid="4337a281-fbaf-49cf-af9a-0e14201d5d5b"/>
<textFieldExpression><![CDATA[$F{dataIntervento}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="180" y="0" width="100" height="30" uuid="7bd7832d-665d-4a8e-af00-004ab5586803"/>
<textFieldExpression><![CDATA[$R{coan.intervento.voce.list}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="300" y="0" width="100" height="30" uuid="5edf1da6-5172-46aa-809a-ed287cf9411b"/>
<textFieldExpression><![CDATA[$R{coan.intervento.durataIntervento.list}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="430" y="0" width="100" height="30" uuid="cff409d1-5834-4597-81ee-85236a29d773"/>
<textFieldExpression><![CDATA[$R{coan.intervento.dataIntervento.list}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="60" width="100" height="30" uuid="7fbbf46d-c93e-478a-9880-53bb4caae1d5"/>
<textFieldExpression><![CDATA["Totale Ore ="]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="90" width="100" height="30" uuid="b52dfdc1-22a2-4d51-b4ba-dbaf13eaeb14"/>
<textFieldExpression><![CDATA["Di cui lavorate ="]]></textFieldExpression>
</textField>
</band>
</groupFooter>
</group>
<title>
<band height="30" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="250" height="30" uuid="5dc33e9c-3e91-42c8-8639-e2b3b0c8f60e"/>
<textFieldExpression><![CDATA[$R{coan.repFattIntDip.titolo.list}]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>
它的示例XML文件:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<list>
<intervento>
<id>64153</id>
<dataIntervento>2017-02-16T00:00:00+01:00</dataIntervento>
<durata>2.0</durata>
<dipendente>
<id>82</id>
<lastUpdate>2012-06-18T15:09:41.206+02:00</lastUpdate>
<utenteLog_id>9185</utenteLog_id>
<nome>EMANUELE</nome>
<cognome>RAGNI</cognome>
<titolo>PROGRAMMATORE</titolo>
</dipendente>
<commessa>
<autocompleteView>AMMORTAMENTI - AMMORTAMENTI</autocompleteView>
<codice>AMMORTAMENTI</codice>
<descrizione>AMMORTAMENTI</descrizione>
<id>49377</id>
<lastUpdate>2016-04-14T13:04:22.871+02:00</lastUpdate>
<utenteLog_id>9185</utenteLog_id>
<chiusa>false</chiusa>
<codiceDestinazione>AMM AMMORTAMENTI E SVALUTAZIONI</codiceDestinazione>
<commessaTipo>
<autocompleteView>MCI - MATERIALI E COSTI INDIVISIBILI</autocompleteView>
<codice>MCI</codice>
<descrizione>MATERIALI E COSTI INDIVISIBILI</descrizione>
<id>70</id>
</commessaTipo>
<destinazione>
<autocompleteView>AMM - AMMORTAMENTI E SVALUTAZIONI</autocompleteView>
<codice>AMM</codice>
<descrizione>AMMORTAMENTI E SVALUTAZIONI</descrizione>
<id>49422</id>
<lastUpdate>2016-04-14T13:03:05.182+02:00</lastUpdate>
<utenteLog_id>9185</utenteLog_id>
<tipo>1</tipo>
</destinazione>
</commessa>
<voce>
<autocompleteView>Ass_sist - assistenza tecnica e sistemisticaaas</autocompleteView>
<codice>Ass_sist</codice>
<descrizione>assistenza tecnica e sistemisticaaas</descrizione>
<id>47399</id>
<lastUpdate>2017-02-06T12:29:58.823+01:00</lastUpdate>
<utenteLog_id>3</utenteLog_id>
<costi>false</costi>
<dipendenti>false</dipendenti>
<ricavi>true</ricavi>
</voce>
<dipendenteNome>EMANUELE RAGNI</dipendenteNome>
<commessaCodice>AMMORTAMENTI - AMMORTAMENTI</commessaCodice>
<voceCodice>Ass_sist - assistenza tecnica e sistemisticaaas</voceCodice>
</intervento>
<intervento>
<id>64131</id>
<dataIntervento>2017-02-14T00:00:00+01:00</dataIntervento>
<durata>2.0</durata>
<dipendente>
<id>81</id>
<nome>MATTEO</nome>
<cognome>BERELLINI</cognome>
<titolo>SOCIO</titolo>
</dipendente>
<commessa>
<autocompleteView>AMM - AMMINISTRAZIONE</autocompleteView>
<codice>AMM</codice>
<descrizione>AMMINISTRAZIONE</descrizione>
<id>68</id>
<lastUpdate>2017-02-14T10:39:29.535+01:00</lastUpdate>
<utenteLog_id>9520</utenteLog_id>
<chiusa>false</chiusa>
<cliente>
<autocompleteView>CRNCST74M01I653T-972712 - TABACCHERIA DI CERIONI CRISTIANO </autocompleteView>
<codice>CRNCST74M01I653T-972712</codice>
<descrizione>CRNCST74M01I653T-972712</descrizione>
<id>46758</id>
<anagrafica>TABACCHERIA DI CERIONI CRISTIANO </anagrafica>
<codiceAnagraficaCategoria></codiceAnagraficaCategoria>
<codiceAnagraficaCategoria2></codiceAnagraficaCategoria2>
<codiceAnagraficaCategoria3></codiceAnagraficaCategoria3>
<codiceBanca></codiceBanca>
<codiceBancaTerzi></codiceBancaTerzi>
<codiceCodiceIva></codiceCodiceIva>
<codiceCodiceRivalsa></codiceCodiceRivalsa>
<codiceDestinatarioPrivati>0000000</codiceDestinatarioPrivati>
<codiceFiscale>CRNCST74M01I653T</codiceFiscale>
<codiceLingua></codiceLingua>
<codiceModTras></codiceModTras>
<codicePagamento></codicePagamento>
<codiceValuta></codiceValuta>
<codiceVettore></codiceVettore>
<disabledCreaProfilo>false</disabledCreaProfilo>
<fax></fax>
<flagAnagraficaFatturazionePred>false</flagAnagraficaFatturazionePred>
<flagAnagraficaSpedizionePred>false</flagAnagraficaSpedizionePred>
<flagCliente>true</flagCliente>
<flagFornitore>true</flagFornitore>
<flagIvaPerCassa>false</flagIvaPerCassa>
<flagProfiloCreato>true</flagProfiloCreato>
<indirizzo>P.ZZA DELLA LIBERTà,3 </indirizzo>
<mysondId>972712</mysondId>
<partitaIva>02370740421</partitaIva>
<partitaIvaInternazionale>IT</partitaIvaInternazionale>
<personaFisica>false</personaFisica>
<sito></sito>
<stato>1</stato>
<telefono1></telefono1>
</cliente>
<codiceCliente>CRNCST74M01I653T-972712 TABACCHERIA DI CERIONI CRISTIANO </codiceCliente>
<codiceDestinazione>AM AMMINISTRAZIONE</codiceDestinazione>
<commessaTipo>
<autocompleteView>AM - AMMINISTRAZIONE</autocompleteView>
<codice>AM</codice>
<descrizione>AMMINISTRAZIONE</descrizione>
<id>71</id>
</commessaTipo>
<descrizioneCliente>null null</descrizioneCliente>
<destinazione>
<autocompleteView>AM - AMMINISTRAZIONE</autocompleteView>
<codice>AM</codice>
<descrizione>AMMINISTRAZIONE</descrizione>
<id>74</id>
<lastUpdate>2015-11-19T12:58:50.607+01:00</lastUpdate>
<utenteLog_id>9185</utenteLog_id>
<tipo>3</tipo>
</destinazione>
</commessa>
<voce>
<autocompleteView>Ass_sist - assistenza tecnica e sistemisticaaas</autocompleteView>
<codice>Ass_sist</codice>
<descrizione>assistenza tecnica e sistemisticaaas</descrizione>
<id>47399</id>
<lastUpdate>2017-02-06T12:29:58.823+01:00</lastUpdate>
<utenteLog_id>3</utenteLog_id>
<costi>false</costi>
<dipendenti>false</dipendenti>
<ricavi>true</ricavi>
</voce>
<dipendenteNome>MATTEO BERELLINI</dipendenteNome>
<commessaCodice>AMM - AMMINISTRAZIONE</commessaCodice>
<voceCodice>Ass_sist - assistenza tecnica e sistemisticaaas</voceCodice>
</intervento>
</list>
适合它的适配器,如果有需要:
<?xml version="1.0" encoding="UTF-8" ?>
<xmlDataAdapter class="net.sf.jasperreports.data.xml.XmlDataAdapterImpl"><name>InterventiDipendente</name><dataFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="repositoryDataLocation"><location>C:\Users\rbroccoletti\Desktop\interventi.xml</location></dataFile><useConnection>true</useConnection><namespaceAware>false</namespaceAware><datePattern>yyyy-MM-dd'T'HH:mm:ss</datePattern><selectExpression>/</selectExpression><locale xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:java="http://java.sun.com" xsi:type="java:java.lang.String">en_US</locale><timeZone xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:java="http://java.sun.com" xsi:type="java:java.lang.String">Europe/Berlin</timeZone></xmlDataAdapter>
答案 0 :(得分:0)
我设法找出了我所遗漏的内容 - 在我传递的.dataSource(query)
上调用JRXmlDataSource
。 REPORT_DATA_SOURCE
以这种方式无法使用,因为它已成为无法使用SortedDataSource
,我从自定义参数中提取它时忘记了这一额外步骤。