Example 2: Importing from a class file

In addition to Example 1, another example of applying the feature of importing parameter values is to specify your required default values. When you group/sort data dynamically with a parameter, when viewing the report, a dialog will be displayed, in which you will find many default values in the drop-down list. However, since you do not need so many values with which to group/sort, you can specify your required default values in a Java class, and then import them. For help, refer to the sample program TestParamList.java in <install_root>\help\samples\APIParameter.

To specify the default parameter values in a class file and then import them, follow the steps below:

  1. Compile TestParamList.java to generate TestParamList.class, and store the class file in <install_root>\help.
  2. Append <install_root> to the ADDCLASSPATH variable of setenv.bat in <install_root>\bin.
  3. Start JReport Designer.
  4. Create a report with a dynamic group/sort using the parameter ImportPara (for details, see Grouping data dynamically and Sorting data dynamically).
  5. Set the report property Parameter List Auto to true in the Report Inspector, and view the report. Many values will be listed in the Enter Parameter Values dialog.
  6. Set Parameter List Auto to false, Import Parameter Value to TestParamList, and view the report again. You will now see that only four values are displayed as defined in TestParamList.java.

Note: If you want to use a parameter as grouping/sorting criteria, you will need to make sure that the parameter values are within the columns used in the report's query. In addition, the name should be consistent with the column names defined in the catalog. For example, the query of the report joins two tables: Orders and Orders Detail. In the Catalog Browser, expand the query used by the report. You will then see all the columns from the two tables. Make sure that the values returned are within them and consistent with the column names.