BackPrevious Page Next PageNext

Importing Parameter Values

When you view a report with parameters, the Enter Parameter Values dialog will be displayed, showing the parameters the report uses for you to input values. The default values shown in the dialog are fixed at development time. However, showing a default, fixed value often is not useful to users.

JReport provides an interface for importing different default values from an outside class file so that the default values can be specified flexibly. There is only one method for this interface: public Hashtable promptValues(String paramsName[]);

Reference: JReport Javadoc jet.util.ImportParamValues interface in <install_root>\help\api.

The following are the general steps for importing parameter values from a class file:

  1. Define a Java class file. For help, see the sample program ParamTest.java and TestParamList.java in <install_root>\help\samples\APIParameter. To import parameter values, implement the interface jet.util.ImportParamValues in your Java file. The class definition may be as follows:
    package help.;
    import java.util.*;
    import jet.util.*;
    public class ParamTest implements ImportParamValues
    {
        public ParamTest()
        {
            //Class body
        }
        public Hashtable promptValues(String paramsName[])
        {
            //Class body
        }
    }
    

    The following explains the code:

  2. Compile the Java file to generate the class file.
  3. Append the class path to the ADDCLASSPATH variable of the file setenv.bat/setenv.sh in <install_root>\bin for both JReport Designer and JReport Server.
  4. Start JReport Designer with the modified batch file.
  5. Open the report with the parameter value that you want to import.
  6. In the Report Inspector, set the property Import Parameter Values of the report to be the class name that you just generated with the package name, and set Parameter List Auto to false.

The following two examples explain how to import parameter values and what you should be aware of while using this feature.

Example 1: Importing from a database

Example 2: Importing from a class file

Example 1: Importing from a database

In the sample program ParamTest.java in <install_root>\help\samples\APIParameter, different values were assigned to the parameter p_StartDate by accessing values from an HSQL database. We will create a report based on a query using this parameter in the query condition and use this report to explain how to import parameter values from a database, so that you do not need to type in the values one by one while specifying the parameter default value (note that in this example we assume your JReport Designer is installed in the default path, that is C:\JReport\Designer).

Note that in the sample ParamTest.java, we use the method compareToIgnoreCase() to compare the parameter name in the class file with the one in your report. This method is not case sensitive when performing the comparison.

  1. Open the catalog file SampleReports.cat in C:\JReport\Designer\Demo\Reports\SampleReports.
  2. Create a page report with a group above table in it based on the query CascadeParameter in Data Source 1. The table displays the following fields: Order Date and Order ID, is grouped by Shipper Territory, and takes the Basic (Default) report style. Save the report as Report1.
  3. Compile ParamTest.java to generate ParamTest.class, and store the class file in C:\JReport\Designer\help.

    javac -classpath c:\JReport\Designer\lib\JREngine.jar; ParamTest.java
  4. Append C:\JReport\Designer\help to the ADDCLASSPATH variable of setenv.bat in C:\JReport\Designer\bin.
  5. Restart JReport Designer and open Report1.
  6. In the Report Inspector, find the report property Import Parameter Values, and input the class name with the full package name. In this example, input help.ParamTest, and then set the property Parameter List Auto to false.

    Tip: The report node is not shown in the resource tree of the Report Inspector by default. To have it shown, select the report tab node in the tree (in this example, the report 1 node), and then click the Up button Up button on the Report Inspector toolbar.

  7. Save the report and catalog, and then view the report result.
  8. In the Enter Parameter Values dialog, click the drop-down list of the parameter. You will find that all the values you specified in ParamTest.java have been imported into the list.
  9. Select one of the values with which to view the report.
  10. Publish the saved report Report1 to JReport Server (for details, see Publishing resources remotely).
  11. Append C:\JReport\Designer\help to the ADDCLASSPATH variable of setenv.bat in <server_install_root>\bin.
  12. Start JReport Server with the modified batch file.
  13. Load your web browser to access the JReport Server Console Page. You will then have the same parameter values as you did in JReport Designer.

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.

Notes:

BackPrevious Page Next PageNext