Programming using the BIRT Reporting APIs : Generating reports from an application : Accessing a report parameter : How to set the value of a known report parameter
 
How to set the value of a known report parameter
The code sample in Listing 12‑6 shows how to set the value of a report parameter that has a known name. 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 object of type IReportRunnable. This sample does not show details of code for retrieving the parameter value from a user interface or a database. The code to perform these tasks depends on your application’s requirements.
Listing 12‑6 Setting the value of a single parameter
// Create a parameter definition task.
IGetParameterDefinitionTask task = engine.createGetParameterDefinitionTask( runnable );
// Instantiate a scalar parameter.
IScalarParameterDefn param = (IScalarParameterDefn) task.getParameterDefn( "customerID" );
// Get the default value of the parameter. In this case,
// the data type of the parameter, customerID, is Double.
int customerID = ((Double) task.getDefaultValue( param )).intValue( );
// Get a value for the parameter. This example assumes that
// this step creates a correctly typed object, inputValue.
// Set the value of the parameter.
task.setParameterValue( "customerID", inputValue );
// Get the values set by the application for all parameters.
HashMap parameterValues = task.getParameterValues( );
// Close the parameter definition task.
task.close( );