BackPrevious Page Next PageNext

Specifying Parameter Values

Setting values of multi-value parameters

Setting dynamic parameter values

When you run or schedule a report via API, if the report contains parameters, you need to specify the parameter values. This topic is about setting parameter values.

Setting values of multi-value parameters

Take the following example to set values to a multi-value parameter Customers_Country:

String[] a = {"USA", "Canada"};
props.put(APIConst.TAG_PARAM_PREFIX + "Customers_Country", a);

If you want the parameter to use all its values, take the following:

props.put(APIConst.TAG_PARAM_PREFIX + "Customers_Country", new String[]{APIConst.MULTIPLE_ALL_VALUE});

For the API code of running a report, see APIDemoRunReport.java in <install_root>\help\samples\APIServer.

Setting dynamic parameter values

You can specify dynamic parameter values by implementing the ParameterGenerator interface. See JReport Javadoc in <install_root>\help\api for detailed usage of the API.

To set dynamic parameter values to a report:

  1. Create a class MyParameterGeneratorImpl to implement the ParameterGenerator interface. See the API demo DemoParameterGenerator.java in <install_root>\help\samples\APIParameter for an example of implementing the ParameterGenerator interface.
  2. Add the class path into the class path of your implementation of running or scheduling the report such as DemoParameterRunReport.
  3. In DemoParameterRunReport, replace the way of setting static parameter values and instead set dynamic values of the required parameters in the report. Take the parameter PToday for example:

    First disable or delete the line:

    props.put(APIConst.TAG_PARAM_PREFIX + "PToday", "2007-5-21");

    and then add a line as follows:

    props.put(APIConst.TAG_PARAM_PREFIX + "PToday", APIConst.TAG_PARAM_GEN_PREFIX + "MyParameterGeneratorImpl";

BackPrevious Page Next PageNext