JasperReports: Unterschied zwischen den Versionen

Aus Wiki - Jochen Hammann
Zur Navigation springen Zur Suche springen
 
(4 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
__TOC__
== Verwenden einer Java Beans Collection Data Source in Subreports ==
== Verwenden einer Java Beans Collection Data Source in Subreports ==


Zeile 5: Zeile 8:


== Verwenden einer XML Data Source in Subreports ==
== Verwenden einer XML Data Source in Subreports ==


Zur Übergabe einer XML Data Source in einen Subreport können wahlweise folgende Expressions spezifiziert werden.
Zur Übergabe einer XML Data Source in einen Subreport können wahlweise folgende Expressions spezifiziert werden.
Zeile 13: Zeile 17:
new net.sf.jasperreports.engine.data.JRXmlDataSource("C:/Users/Jochen/JaspersoftWorkspace/STReportBookTemplate/Report.xml", "/reportSchedule")
new net.sf.jasperreports.engine.data.JRXmlDataSource("C:/Users/Jochen/JaspersoftWorkspace/STReportBookTemplate/Report.xml", "/reportSchedule")
</syntaxhighlight>
</syntaxhighlight>


== JRXmlDataSource - subDataSource() vs. dataSource() ==
== JRXmlDataSource - subDataSource() vs. dataSource() ==
Zeile 18: Zeile 23:
Die JavaDoc API Beschreibung sagt folgendes dazu:
Die JavaDoc API Beschreibung sagt folgendes dazu:
:: ''To support subreports, sub data sources can be created. There are two different methods for creating sub data sources. The first one [subDataSource()] allows to create a sub data source rooted at the current node. The current node can be seen as a new document around which the sub data source is created. The second method [dataSource()] allows to create a sub data source that is rooted at the same document that is used by the data source but uses a different XPath select expression.''
:: ''To support subreports, sub data sources can be created. There are two different methods for creating sub data sources. The first one [subDataSource()] allows to create a sub data source rooted at the current node. The current node can be seen as a new document around which the sub data source is created. The second method [dataSource()] allows to create a sub data source that is rooted at the same document that is used by the data source but uses a different XPath select expression.''


Beispiel:
Beispiel:
Zeile 35: Zeile 41:
</reportSchedule>
</reportSchedule>
</syntaxhighlight>
</syntaxhighlight>


Der entsprechende Subreport ist mit folgender Datenquelle verknüpft:
Der entsprechende Subreport ist mit folgender Datenquelle verknüpft:
<syntaxhighlight lang="text">
((net.sf.jasperreports.engine.data.JRXmlDataSource) $P{REPORT_DATA_SOURCE}).subDataSource("/reportSchedule/reports/report[1]/widget[1]")
((net.sf.jasperreports.engine.data.JRXmlDataSource) $P{REPORT_DATA_SOURCE}).subDataSource("/reportSchedule/reports/report[1]/widget[1]")
</syntaxhighlight>
D.h. innerhalb des entsprechenden Subreports gilt folgender XPath:
D.h. innerhalb des entsprechenden Subreports gilt folgender XPath:
<syntaxhighlight lang="text">
/reportSchedule/reports/report[1]/widget[1]
/reportSchedule/reports/report[1]/widget[1]
</syntaxhighlight>
Enthält der Subreport eine Tabelle oder einen weiteren Subreport, so muss diesem z.B. zur Darstellung aller Items folgende Sub Data Source übergeben werden:
Enthält der Subreport eine Tabelle oder einen weiteren Subreport, so muss diesem z.B. zur Darstellung aller Items folgende Sub Data Source übergeben werden:
<syntaxhighlight lang="text">
((net.sf.jasperreports.engine.data.JRXmlDataSource) $P{REPORT_DATA_SOURCE}).subDataSource("widget/data/item")
((net.sf.jasperreports.engine.data.JRXmlDataSource) $P{REPORT_DATA_SOURCE}).subDataSource("widget/data/item")
</syntaxhighlight>
oder
oder
<syntaxhighlight lang="text">
((net.sf.jasperreports.engine.data.JRXmlDataSource) $P{REPORT_DATA_SOURCE}).dataSource("/reportSchedule/reports/report[1]/widget[1]/data/item")
((net.sf.jasperreports.engine.data.JRXmlDataSource) $P{REPORT_DATA_SOURCE}).dataSource("/reportSchedule/reports/report[1]/widget[1]/data/item")
</syntaxhighlight>

Aktuelle Version vom 28. September 2016, 21:39 Uhr


Verwenden einer Java Beans Collection Data Source in Subreports

Siehe Artikel Simple Guide To Sub-reports in JasperReports / iReport.


Verwenden einer XML Data Source in Subreports

Zur Übergabe einer XML Data Source in einen Subreport können wahlweise folgende Expressions spezifiziert werden.

((net.sf.jasperreports.engine.data.JRXmlDataSource) $P{REPORT_DATA_SOURCE}).subDataSource("/reportSchedule")
((net.sf.jasperreports.engine.data.JRXmlDataSource) $P{REPORT_DATA_SOURCE}).dataSource("/reportSchedule")
new net.sf.jasperreports.engine.data.JRXmlDataSource("C:/Users/Jochen/JaspersoftWorkspace/STReportBookTemplate/Report.xml", "/reportSchedule")


JRXmlDataSource - subDataSource() vs. dataSource()

Die JavaDoc API Beschreibung sagt folgendes dazu:

To support subreports, sub data sources can be created. There are two different methods for creating sub data sources. The first one [subDataSource()] allows to create a sub data source rooted at the current node. The current node can be seen as a new document around which the sub data source is created. The second method [dataSource()] allows to create a sub data source that is rooted at the same document that is used by the data source but uses a different XPath select expression.


Beispiel:

<reportSchedule>
	<reports>
		<report title="Title" subtitle="Subtitle">
			<widget title="Title">
				<data>
					<item checkpoint="Checkpoint01" location="Location"/>
					<item checkpoint="Checkpoint02" location="Location"/>
					<item checkpoint="Checkpoint03" location="Location"/>
				</data>
			</widget>
		</report>
	</reports>
</reportSchedule>


Der entsprechende Subreport ist mit folgender Datenquelle verknüpft:

((net.sf.jasperreports.engine.data.JRXmlDataSource) $P{REPORT_DATA_SOURCE}).subDataSource("/reportSchedule/reports/report[1]/widget[1]")


D.h. innerhalb des entsprechenden Subreports gilt folgender XPath:

/reportSchedule/reports/report[1]/widget[1]


Enthält der Subreport eine Tabelle oder einen weiteren Subreport, so muss diesem z.B. zur Darstellung aller Items folgende Sub Data Source übergeben werden:

((net.sf.jasperreports.engine.data.JRXmlDataSource) $P{REPORT_DATA_SOURCE}).subDataSource("widget/data/item")

oder

((net.sf.jasperreports.engine.data.JRXmlDataSource) $P{REPORT_DATA_SOURCE}).dataSource("/reportSchedule/reports/report[1]/widget[1]/data/item")