Example 4: Developing reports with dynamic UDS

JReport Designer supports the Dynamic UDS feature. This feature improves performance significantly by retrieving the selected fields. At runtime, an option is provided for you to pick up the columns you want to see in the report. In this way, JReport Designer generates a dynamic report according to your selection.

In this example, SQLDataSource is used to illustrate the usage and effect of the Dynamic UDS feature. Assume that you have generated SQLDataSource.class, start JReport Designer with the modified batch file (for details, see Compiling and running SQLDataSource).

  1. Open an existing catalog.
  2. In the Data tab of the Catalog Browser, expand the data source to which the UDS is to be added.
  3. Right-click the Parameters node and select Add Parameter from the shortcut menu.
  4. In the Create Parameter dialog, enter the following:
  5. Right-click the data source node, and then select Add User Defined Data Source from the shortcut menu.
  6. In the Add User Defined Data Source dialog, enter the following information:

    The UDS employees will now have been added to the catalog.

  7. Click on the Standard toolbar to open an existing report, and then select File > New > Page Report Tab.
  8. In the New Page Report Tab dialog, specify the name and layout of the report tab as required and then click Create. Here, we choose to create a table report.
  9. In the Data screen of the Table Wizard, check the New radio button and choose the UDS employees from the User Defined node. Then, click Next to go to the next tab.
  10. In the Display screen, add the fields EMPLOYEEID, employees_NOTES, employees_SALARY and HIREDATE to be displayed in the table, edit their display names to ID, Notes, Salary, Hire Date, and then click Next.
  11. In the Group screen, specify to group on the field EMPLOYEEPOSITION.
  12. Skip the Summary screen and in the Layout and Style screen, specify to display the report in the Warm style.
  13. Click Finish to create the report.
  14. Click the View tab to view the report. You will then be prompted to enter a parameter.
  15. Select select * from employee as the parameter, and you will see that data for all fields has been retrieved.

  16. Go back and run this report again. This time, choose select salary from employee. You will notice that no groups are divided and the group name changes to NULL. This is because only the field employees_SALARY has been selected this time. JReport Designer will make no reference to the employees_Position column, on which the group is based.

Note: To make a dynamic UDS work fine, if the SQL statement at runtime doesn't include all the UDS columns, you need to make sure that none of the UDS columns' properties is edited, that is the Specify Columns option in the Add User Defined Data Source dialog should be unchecked, otherwise exceptions will be produced when the SQL statement is used to generate dynamic report from the UDS.