16 December 2009

Jasper Reports - Parameterisation of reports

In the previous article, we updated an existing report on a Jasper Server.

This time, we'll look at how to define user-entered parameters for a report.

To define a set of parameters for a report, you can add parameters using the Report Inspector:

jasper reports add parameter to report

You can define the default values for a report. Once you’ve defined a parameter, you can reuse this elsewhere, for example in the SQL for a report:

jasper reports use parameter in query string

You reference the parameters using $P{name}, in this case $P{table_schema}.

Using this, you can filter the output of a report. But to use them, you need to specify how the user enters them. The entry of values isn’t done in the report, but in the Report Unit. You need to define Report Unit Input Controls.

You can define an Input Control so that the user can specify a parameter for a report. For the report defined previously, you could specify a value for the table_schema.
In the Report Unit, create an Input Control:

jasper reports add input control

Enter the Name and Label :

jasper reports enter input control name

The label will be visible to the user. You need to define the details in the tab Input Control Details. For a list of items from the database, use Single Select Query. You can mark the value as mandatory as well here.

jasper reports input control details

To define the SQL statement, click on the Edit Local Resource button:
You'll need to enter a name and label for the local resource (table_schema/table_schema), and then click on the Query tab to define the SQL:

jasper reports define SQL for input control

If you select a data source of 'None', the data source used will be that defined for the Report Unit. In the tab Value and Visible Columns, you need to define the value which will be passed to the report, and the columns visible which will be displayed to the user:

jasper reports input control columns

After deploying to the server, when you run the report the web site will display a input page.

jasper reports show input control on server

And the report displays the information for the table schema chosen.

jasper reports filtered report


Next we'll look at how to modify the user rights for the reports and other objects on Jasper Server. Next>>

1 comment:

Svyatogor said...

Hi there!

Just wanted to say thank you so much for this plain explanation. I've spend literally hours trying to figure out how the input controls are linked to parameters but everybody seems to take thins knowledge for granted :/

So thanks a lot again!