13.07.2015 Views

iReport Ultimate Guide - Nimsoft Library

iReport Ultimate Guide - Nimsoft Library

iReport Ultimate Guide - Nimsoft Library

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Fields, Parameters, and Variables6.2 Working with ParametersParameters are values usually passed to the report from the application that originally requested it. They can be used forconfiguring features of a particular report during report generation (such as the value to use for a condition in a SQL query)and to supply additional data to the report that cannot properly provided by the data source (e.g., a custom title for the report,an application-specific path to search for images, or even a more complex object like an image).Just as with other report objects, parameters must have a class type and must be declared in the report design (see Figure 6-8).The type of the parameters may be arbitrary, but the parameter name must be unique.Figure 6-8Parameter DefinitionThe property Use as prompt is not used directly by UR. It is a special flag for the parameter that may be used byexternal applications; you can examine the report template to discover what parameters you should use to prompt for input.The Default Value Expression permits you to set a pre-defined value for the parameter. This value will be used if novalue is provided for the parameter from the application that executes the report. The type of value must match the typedeclared in Parameter Class. In this expression it is not possible to use fields and/or variables, since the value of theparameter must be set before fetching the first record from the data source.You may legally define another parameter as the value of Default Value Expression, but this method requires carefulreport design. <strong>iReport</strong> parses parameters in the same order in which they are declared, so a default value parameter must bedeclared before the current parameter. I realize this sounds a bit tricky, but it can be useful to employ a parameter that dependson another one, especially if we want to process it.In the next section we will see how to use a parameter in an SQL query to specify not just the value of a parameter, but a pieceof or even the whole SQL query. This will allow you to dynamically create an input-dependent query to be stored in aparameter.The parameter Description is another attribute that is not used directly by UR, but like the Use as a promptattribute, may be passed to an external application.Finally, just as with fields, you may specify pairs of type name/value as properties for each parameter. This is just a way to addextra information to the parameter, information that will be used by external applications. For example, the designer can useproperties to include the description of the parameter in different languages, or perhaps add instructions about the format of theinput prompt.6.2.1 Using Parameters in a QueryGenerally, parameters can be used in the query associated with a report even if not all the languages support them. In thischapter we will focus on using parameters in SQL queries, which is probably the most common type of query.Suppose we have a report that displays information about a customer. When we generate the report we would need to specifythe ID of the customer to display. In order to get data regarding the customer we need to pass this information to the query; inother words, we want to filter the query to obtain only the data relevant to a particular customer ID. The query will look likethis:select * from customers where CUSTOMERID = $P{MyCustomerId}101

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!