When you run a report with parameters, Logi Report will prompt you the Enter Parameter Values dialog to specify the parameter 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.
Logi Report 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 in this interface: public Hashtable promptValues(String paramsName). For detailed information about its usage, refer to the jet.util.ImportParamValues interface in the Logi Report Javadoc.
The following are the general steps for importing parameter values from a class file:
- 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:
public class ParamTest implements ImportParamValues
public Hashtable promptValues(String paramsName)
The following explains the code:
- The package name can be defined by yourself. In our sample code, we use help as the package name.
- Since the interface ImportParamValues is in the package jet.util, you will have to import the class package jet.util.*.
- A public constructor method without parameters is required.
- Compile the Java file to generate the class file.
- Append the class path to the ADDCLASSPATH variable of the file setenv.bat/setenv.sh in
<install_root>\binfor both Logi Report Designer and Logi Report Server.
- Start Logi Report Designer with the modified batch file.
- Open the report with the parameter value that you want to import.
- 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.
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 Logi Report Designer is installed in the default path, that is
Note that in the sample ParamTest.java, the method compareToIgnoreCase() is used 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.
- Make sure SampleReports.cat is the currently open catalog file. If not select File > Open Catalog to open it from
- 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 detail fields: Order Date and Order ID, is grouped by Shipper Territory, and takes the Basic (Default) report style. Save the report as Report1.
- Compile ParamTest.java to generate ParamTest.class, and store the class file in
javac -classpath C:\LogiReport\Designer\lib\JREngine.jar; ParamTest.java
C:\LogiReport\Designer\helpto the ADDCLASSPATH variable of setenv.bat in
- Restart Logi Report Designer and open Report1.
- In the Report Inspector, find the report property Import Parameter Values and specify the class name with the full package name. In this example, type 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 select the Up button on the Report Inspector toolbar.
- Save the report and catalog, and then view the report result.
- In the Enter Parameter Values dialog, select 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.
- Select one of the values with which to view the report.
- Publish the saved report Report1 to Logi Report Server.
C:\LogiReport\Designer\helpto the ADDCLASSPATH variable of setenv.bat in
- Start Logi Report Server with the modified batch file.
- Load your web browser to access the Logi Report Server console. You will then have the same parameter values as you did in Logi Report Designer.
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 addidtional information, refer to the sample program TestParamList.java in
To specify the default parameter values in a class file and then import them, follow the steps below:
- Compile TestParamList.java to generate TestParamList.class, and store the class file in
<install_root>to the ADDCLASSPATH variable of setenv.bat in
- Start Logi Report Designer.
- Create a report with a dynamic group/sort using the parameter ImportPara.
- 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.
- 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.
- You need to ensure that the parameter format in the class file is consistent with that in Logi Report, specifically, that the parameter format used in the class file is parsed when viewing the report so that the correct data records will be returned.
- When you implement the interface jet.util.ImportParamValues and use its function promptValues(), ensure that:
- The parameter of this function is a String array which contains the names of the parameters.
- The return value of this method is a Hashtable, its keys are parameter names used in the report and its values are vector objects which contain the parameter values.
- When there are subreports in a primary report, setting the properties Import Parameter Value and Parameter List Auto will not affect them. That is, you have to set these properties in the primary report and subreports separately.
- 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 Manager, 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.