Programming using the BIRT Reporting APIs : Generating reports from an application : Accessing a report parameter : How to use the Collection of report parameters
 
How to use the Collection of report parameters
The code sample in Listing 12‑7 shows how to use the Collection of report parameters. The sample uses the ReportParameterConverter class to convert the String values that the user interface supplies into the correct format for the parameter. The sample creates a HashMap object that contains the parameter values to use later to run the report. The variable, engine, is a ReportEngine object. The variable, runnable, is an IReportRunnable object. This sample does not show details of code for retrieving the parameter values from a user interface or a database. The code to perform these tasks depends on your application’s requirements.
Listing 12‑7 Setting the values of multiple parameters without grouping
// Create a parameter definition task.
IGetParameterDefinitionTask task = engine.createGetParameterDefinitionTask( runnable );
 
// Create a flat collection of the parameters in the design.
Collection params = task.getParameterDefns( false );
// Get the default values of the parameters.
HashMap parameterValues = task.getDefaultValues( );
 
// Get values for the parameters. Later code in this example
// assumes that this step creates a HashMap object,
// inputValues. The keys in the HashMap are the parameter
// names and the values are those that the user provided.
 
// Iterate through the report parameters, setting the values
// in standard locale-independent format.
Iterator iterOuter = params.iterator( );
ReportParameterConverter cfgConverter = new ReportParameterConverter( "", Locale.getDefault() );
while ( iterOuter.hasNext( ) ) {
IScalarParameterDefn param = (IScalarParameterDefn) iterOuter.next( );
String value = (String) inputValues.get( param.getName( ));
if ( value != null ) {
parameterValues.put( param.getName( ),
cfgConverter.parse( value, param.getDataType( ) ) );
}
}
// Close the parameter definition task.
task.close( );
Getting the values for cascading parameters
A cascading parameter group contains an ordered set of parameters that provide lists of acceptable values for the end user to select. The value chosen for the first parameter limits the available values for the second one, and so on. The parameters use one or more queries to retrieve the values to display to the user from a data set. The parameter definition task uses the data rows from the queries to filter the values for each parameter, based on the values of preceding parameters in the group. For example, consider a cascading parameter group that uses the following query:
SELECT
PRODUCTS.PRODUCTLINE,
PRODUCTS.PRODUCTNAME,
PRODUCTS.PRODUCTCODE
FROM CLASSICMODELS.PRODUCTS
The group has two parameters, ProductLine on PRODUCTS.PRODUCTLINE and ProductCode on PRODUCTS.PRODUCTCODE. The display text for ProductCode uses values from PRODUCTS.PRODUCTNAME. Figure 12‑1 shows the appearance of the requester that prompts for values for these parameters when a user previews the report in BIRT Report Designer.
Figure 12‑1 Cascading report parameters
To use the report engine API to get the values for cascading parameters, perform the tasks in the following list.
*To populate the list of values for the first report parameter in the group, call IGetParameterDefinitionTask.getSelectionListForCascadingGroup( ). This method takes two parameters, the String name of the parameter group and an array of Object. For the first parameter, this array is empty. The method returns a Collection of IParameterSelectionChoice objects.
*To populate the list of values for further report parameter in the group, call getSelectionListForCascadingGroup( ) again. In this case, the Object[ ] array contains the values for the preceding report parameters in the group. In the example shown in Figure 12‑1, the Object[ ] array is:
new Object[ ] { "Trains" }