JasperReports
Version vom 28. September 2016, 21:32 Uhr von Jochen (Diskussion | Beiträge)
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")