
Importing parameter values
When you are viewing a report set with parameter(s), the Enter Parameter Values dialog will be displayed, showing the parameters the report set uses for you to input a value. The default value(s) shown in the dialog were fixed at the development time. However, showing a default, fixed value which was 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\designer\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\designer\samples. 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()
{
;
}
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 classpath variable of the file JReport.bat in
<install_root>\bin.
- Start JReport Designer with the modified batch file.
- Open the report set with the parameter value that you want to import.
- In the Report Inspector, set the property Import Parameter Values of the report set 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 set level is not displayed in the Report Inspector. You can select any report contained in the report set 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 set 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 set and its values are vector objects which contain the parameter values.
- When there are subreports in a main 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 main 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:
