Issue Description
It is possible pass an XML Datasource to a jrxml's Table Component.
Resolution
The JasperReport Samples can be combined to provide information and examples of passing an XmlDatasource to a Table Component. So we'll reference these:
Subreport example:
http://jasperreports.sourceforge.net/sample.reference/subreport/index.html#subreports
XmlDatasource example:
http://jasperreports.sourceforge.net/sample.reference/xmldatasource/index.html
The files can be used within Studio via File -> New -> Project , browsing to the JasperReports Samples project, then running the report against the "Sample DB" datasource where possible.
Table Components, like charts and crosstabs get their data from "datasets". A dataset is similar to a subreport in many ways, so a table and subreport are very similar. The XmlDataSource sample's CustomersReport calls a subreport, so we can use it as the basis for our table.
In typical subReport element you define either <connectionExpression> or <dataSourceExpression> to specify the source used to populate the sub. (see Subreport example )
In typical table component you specify the dataset via a datasetRun element, like:
<datasetRun subDataset="TableDataset"
(for more info on datasets and datasetruns see the JR Ultimate Guide Datasets chapter)
But as you've seen in XmlDatasource sample, instead of <connectionExpression> , the Xpath query executor (queryString language="xPath") can expect <subreportParameterExpression>$P{XML_DATA_DOCUMENT} . You can do the same thing with table compoments, skip the datasetRun, and just set subreportParameterExpression>$P{XML_DATA_DOCUMENT}
In the attached CustomersXmlMain.jrxml, I edited the XmlDataSource samples main report to remove the subreport and replace it with a table component. To do this I:
Ran the table wizard to get basic field layout.
Then I grabbed the query from the Xmldatasource example's subreport, OrdersReport.jrxml:
<queryString language="xPath"> <![CDATA[/Northwind/Orders[CustomerID='$P{CustomerID}']]]>
Created a parameter for the table's dataset
Edited the jrxml source, modifying the datasetRun to have three parameters, one for the parameterized query, the others for the Xpath executor:
<datasetParameter name="CustomerID"> <datasetParameterExpression> <![CDATA[$F{CustomerID}]]> </datasetParameterExpression> </datasetParameter> <datasetParameter name="XML_DATA_DOCUMENT"> <datasetParameterExpression> <![CDATA[$P{XML_DATA_DOCUMENT}]]> </datasetParameterExpression> </datasetParameter> <datasetParameter name="XML_DATE_PATTERN"> <datasetParameterExpression> <![CDATA["yyyy-MM-dd-HH"]]> </datasetParameterExpression> </datasetParameter>
References:
http://community.jaspersoft.com/documentation/jasperreports-library-ultimate-guide
Ref. Case 01438960
Recommended Comments
There are no comments to display.