Example 3: XML file with dynamic parameters
When you design a report from the tables imported through OOJDBC, and the tables have the same input parameters, but you don't want to input the same parameters again, JReport provides a way to allow you to bind parameters in a catalog, so they can share the same parameter value.
This example demonstrates how to import tables with dynamic parameters from the ODF file generated by the Model Wizard.
Importing the XML file using the Model Wizard
To import an XML file with the Model Wizard, take the following steps:
- Run ModelWizard.bat in
<install_root>\bin
. The Object Source Wizard will then appear.
- Add two tables as shown in Example 1. The first table named employee1 has one String type column, and the second table named employee2 has one Int type column. They have the same input parameter for param0. The default value is
h:\xml\employee.xml
. Make sure to check the option Is Dynamic.
- In the Object Source Wizard, click File > Save. You will then be prompted to save the ODF file. You should save it to
<install_root>\lib
or the directory where the catalog will be. Here we save it as xmlparam.odf.
Notes:
- If you choose the option Is Dynamic, this parameter will be passed to JReport Designer. After you create a new connection, you will find this parameter in the node Parameters in the Catalog Browser.
- The same ODF file cannot exist in
both <install_root>\lib
and the directory where the catalog is to be located.
Importing the ODF file into a catalog
To import the generated ODF file into a JReport catalog, take the following steps:
- Start JReport Designer.
- Click File > Catalog Management > New Catalog.
- In the Input New Catalog Name dialog, specify the catalog name, the data source name and the path. The catalog should be located in the directory where you saved the ODF file. For example, if you saved the ODF file in
C:\odf
, the new catalog should be created also in C:\odf
.
- In the Catalog Browser, create a parameter that is of String data type and is named path. This parameter will be bound to the parameters in the tables that were imported through OOJDBC.
- Create a new connection in the Get JDBC Connection Information dialog as follows:
- The Add Table dialog appears prompting you to add the listed tables. Select the table employee1 and click the Add button. The Dynamic Parameter used in oojdbc tables dialog will then be displayed. Uncheck the checkbox in the New column and select the parameter path from the drop-down list to bind param0 to the parameter path.
- Repeat the above step to add the employee2 table and bind its parameter param0 to the parameter path. Now the parameters in the two tables will share the same parameter path.
- Click the New Page Report button on the Standard toolbar to develop a report on the newly inserted tables.
- When viewing the report, the Enter Parameter Values dialog will be displayed, asking you to input the parameter. You will only need to input the path of imported XML file once since the parameter is shared with the parameters in the two tables.
Modifying the dynamic parameters
You can modify the links between the parameters in OOJDBC and parameters in the JReport catalog. To do this:
- Launch the Catalog Browser in JReport Designer.
- Select the table with the dynamic parameters that are to be modified. Right-click on the specified table, and then select Parameters from the shortcut menu.
- Highlight the parameter in the catalog, and then select the parameter from the drop-down list to bind it to the parameter in OOJDBC.