Binding a parameter to a DBField
JReport provides a mechanism which links each field value of a "display column" with the exact value of a "bind column". When you select the field value from the "display column", the field value of the "bind column" is sent to the query to filter the query result.
For example, if you specified customer ID to query data, but you would like to select customer name not customer ID in the parameter specifying dialog which appears at runtime, you can do so by using the functionality - Parameter Binding.
- Open the demo catalog SampleReports.cat and in the Catalog Browser, expand the data source where to create the parameter.
- Right-click the Parameters node and then click Add Parameter.
- In the Create Parameter dialog, enter BindColumn in the Name field, select Bind with Single Column from the Value Setting drop-down list, select Tables and Views from the Source drop-down list, then select Customer ID from the Bind Column drop-down list, and choose Customer Name from the Display Column drop-down list.
Note: Selecting a display column different from the bind column will establish a link between the two columns (DBFields). When you select the field value from the display column, the corresponding field value of the bind column is actually assigned to the parameter.
- In the same data source, create a query CustomersInfo on the table Customers. Select all the fields contained in the table.
- Create a standard banded report based on the query, and have the fields Customer ID, Customer Name, City and Phone displayed in the report.
- In the Resource View panel, right-click the node that represents the query, and then select Edit Query from the shortcut menu.
- In the Query Editor, click Query > Filter.
- In the Search Condition dialog, add a condition for the query as follows (for details, see Filtering with the filter format):
- Click OK to apply the changes to the query.
- Click the View tab to view the report. All the customer names will be listed in the Enter Parameter Values dialog. You can select a value from the list to query data with the customer ID instead of customer name.