Creating links with JHyperlink

JHyperlink can be used to create hyperlinks in reports. This section shows you two specific examples about using JHyperlink:

Example 1: Building hyperlinks by using JHyperlink

Sometimes you have built a number of reports and each of them contains different information about the same subject. You may want to build a summary report to organize these reports together. For example, Report A is Summary Information of City Wise, while Report B is an Account List of City Wise. When you click on the city in Report A, it should go to the page of that city in Report B. With this hyperlink feature, you can build hyperlinks among reports. In addition, you can also insert any hyperlink to be invoked. In any case, a web browser will be displayed to view the specified pages.

  1. Start JReport Designer and open the report in which you want to build a hyperlink.
  2. On the menu bar, click Insert > UDO.
  3. In the Insert UDO dialog, select JHyperLink from the drop-down list, and then click OK. You will then be able to insert a hyperlink into the report.
  4. Keep the JHyperlink focused, and then go to the Report Inspector.
  5. Input http://localhost:8888 in the value cell of the URL property as the JReport Enterprise Server address, make sure the Executer Class Name value is jet.udos.IEExecuter, and then type JReport Enterprise Server in the Display Value property value cell as the display name of the hyperlink. See illustration.
  6. Insert another hyperlink using the same way and define its properties in the Report Inspector as follows:

    Two hyperlinks have been successfully built into the report.

  7. In view mode, click the JReport Enterprise Server hyperlink that you just made. It will bring out a browser session to connect with JReport Enterprise Server. Make sure that you have launched JReport Enterprise Server and that the URL corresponds with your server configuration.
  8. Click the Website hyperlink. You will then see the http://www.jinfonet.com home page in a web browser.

Notes: After you insert a JHyperlink into a report which is to be exported to PDF, Excel or HTML, you can specify whether to make the hyperlink effective by setting a property which corresponds to the format type. Respectively, they are: Enable Hyperlink in PDF for PDF, Enable Hyperlink in Excel for Excel and Enable Hyperlink in HTML for HTML.

Example 2: Linking reports as master/detail reports by using JHyperlink

JHyperlink can be used to link reports as master and detail reports to show related information in a hierarchy, such as Orders and Line Items. You can use the JHyperlink object to control the URL to show the information in the detail reports on JReport Enterprise Server. For how to use JHyperlink to link reports as master/detail reports, JReport Designer provides an example for your better understanding.

All the needed materials for this example, including the report sets and catalog are compressed in the file JHyperlink_Master-detail.zip in <install_root>\help\designer\samples. Extract JHyperlink_Master-detail.zip to <install_root>\help\UDODemo, and do the following steps:

  1. In JReport Designer, open the catalog for this example, Demo.cat.
  2. Select one of the existing report sets and ensure the report sets in this catalog can run. If there is a problem, open the Catalog Browser, highlight the connection node, and in the Properties sheet, modify the value of the URL to connect to the demo database, it is jdbc:hsqldb:<install_root>\help\UDODemo\db\demo.

Linking the master report to the detail report

Formulas will be used to control the property values URL and Display Value of JHyperlink to make it link the master and detail reports.

  1. Open the report set that contains the master report - mainreport.cls.

    A JHyperlink is inserted in the Detail panel of the report. The URL and Display Value property values of the UDO are as follows:

  2. Open the report set that contains the detail report SalesPerformancebyYear.cls.

    In the GroupHeader panel, the value of Total is a JHyperlink, whose property values URL and Display Value are both controlled by formulas.

Running the master/detail reports on JReport Enterprise Server

This example requires you to access the report by URL, you can drill the reports up and down. To do this:

  1. Start JReport Enterprise Server.
  2. Publish the report sets and catalog to JReport Enterprise Server.
  3. Run the master report mainreport.cls in JReport Web. See illustration.
  4. Click any name in the Employee Name column, and the year's performance of the employee will be displayed. See illustration.
  5. Click the Total number, and it will drill down to the next detail report. See illustration.

Note: When using JHyperLink to link a report and a parameter with special characters such as "\" and "&" is used in the URL, you need to add "\" before the special character.

For example:

If Parameter=a&b, make it: Parameter=a\&b

If Parameter=a\b, make it: Parameter=a\\b