( Digital Gene )
A feature released in version 5.6 of JasperReports Server is the ability to create your own custom link types in reports. These link types can be anything you like and the code the fires also can be anything you want. You may be familiar with the ReportExecution link type available from with in JasperReports. This function tells JasperReports Server to execute a report and is passed some parameters to help make this happen. Well, how cool would it be if you could actually write your own functions and pass any parameters you want into it? Pretty Cool I think and this is what I’ll show you how to do! Let’s layout the steps involved to pull this off.
- Create a report in Jaspersoft Studio. Currently (as of this article) the only way to place a link inside a report is via Jaspersoft Studio.
- Find the section(s) of the report you want to offer this link functionality and add a hyperlink. I’ll show you some examples below.
- In the hyperlink(s) you will pass in your new custom link name. This really is the function that will run when this link is clicked.
- Place this file in the proper location of your JasperReports Server install
That’s pretty much it! It’s really not complicated at all and works very well. So let’s start looking at these steps in detail one at a time.
Here is an example of a report created in JasperSoft Studio. This is a very simple report that opens up dialog boxes from 3 different locations.
Here is a picture of the content being presented in the dialog. Report parameters and even Java code are all good.
Dialogs 2 and 3 - Both of these links open up dialog boxes that show actual data from the report. Notice how each link is within a row of data. This means that each link can pass parameters specific to that row! Very cool indeed :) So the links you see here are actually going to be passing report parameters and are completely dynamic. See the images below and how the Employee Details dialog boxes both render different data.
Here is a picture of the content parameter that is being passed into the open_dialog function. Notice how report fields are being passed in. This will allow each link to be unique and have it’s own set of values for the provided parameters.
Once this report has been uploaded into JasperReports Server it will look like the below image. By clicking on the links different dialog boxes will open. You can look into the code I’m providing to see how this works and how you can open multiple dialog boxes as well as have multiple links update/change the content in the same dialog box.
To test out this example and see how the code works please download the example from the link below.
I hope you have fun with this feature and create some really cool reports with JasperSoft!!!
BlogId - 0f15151c-4b21-4b87-9d1a-61f4fe11e74f