Introduction
This article applies to iReport Designer v5.6.1 and previous versions. It will not work in any version of Jaspersoft Studio or in iReport Designer v6.0.x.
The purpose of this article is to describe how to use parameters in queries when using iReport to design a report from a Domain datasource.
The article is written for an advanced user of iReport and JasperReports Server to use, it's meant to be more of a primer than a complete document.
Query
Domain based queries use the DomEL language to query data. It's not SQL and therefore you can not use the same syntax for parameters, for example, parameters do not need the $P{syntax}, instead the field name is referenced.
In the following example, we have a parameter declared in the JRXML called $P{prev_year}, the way to use that parameter is shown below:
<query> <queryfields><queryfield id="total_apps"></queryfield></queryfields> <queryfilterstring>newSet2.Year == prev_year</queryfilterstring></query>[/code]
Collections
Collections or sets can be used as well. You can create a parameter that is a collection and put it in the query with the "in" operator. Refer to section 8.2.3 of the JasperReports Server User Guide
Also, multi-select input controls can be populated by a Domain based query
Populating from the Server
It is also possible to populate the values of an import control from a query. Typically I would recommend prototyping this using the ad-hoc editor - create a ad-hoc view with a filter on the column you want to use. Create a report from the view and then in iReport you can see how it's set up.
Here's one example:
<!--?xml version="1.0" encoding="UTF-8"?--><query xmlns="http://www.jaspersoft.com/2007/SL/XMLSchema"> <grouplist> <group columnname="newSet1.region"></group> </grouplist> <queryfields> <queryfield id="newSet1.region"></queryfield> </queryfields></query>[/code]
Here's the example in iReport:
The "value" and "name field" would come from newSet1.region in this case
See Also
- Section 8.2 of the JasperReports Server User Guide discussed the DomEL language in full detail
- Other Articles about the Domain Expression Language (DomEL)
Recommended Comments
There are no comments to display.