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 the development time. However, showing a default, fixed value which is dated makes no sense 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:
- Define a Java class file. For help, see our sample programs 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:
- 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 in
<install
_root>\bin
.
- Start JReport 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.
Notes:
- Be default, the node that represents the report level is not displayed in the Report Inspector. You can select any report tab contained in the report in the tree first and then click the Up button on the toolbar to make it displayed.
- Ensure that the parameter format in the class file is consistent with that in JReport, 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.
The following two examples explain how to import parameter values and what you should be aware of while using this feature: