i-net Clear Reports

Implementation as Standalone Java Application

If you like to integrate i-net Clear Reports and the Java report viewer (cc-viewer.jar) in your Java standalone application you need to add the following code to your Java application.

At first you need to start the report listener in your application. After the report listener started it is listening for report requests from clients. If a new report request has been received the listener will do the following:

  • Open a new socket for this report request
  • Create a new engine for the report request if necessary or if an engine for this report already exists in the engine pool then the engine from the pool will be used.
  • Send the parameter from the request to the engine
  • Send the executed report back to the viewer (client)

The following line starts the report listener thread:

// Create the Listener that listens for report requests and
// that gives the report request to the engine
 
// The parameter true tells the listener that it is a listener in a Java standalone application.
// The listener in a Java standalone application can use the next
// free TCP/IP port if the port that number is specified in the configuration is currently in use.
//So it is possible to start multiple Java standalone applications on the same computer.
static Listener reportListener = new Listener(true);

Tip: Add this line to the main class (java file that contains the main() method) of your Java application.

The next step is to add the Java report viewer (SwingReportViewer) to your application. For instance, this can be accomplished in the actionPerformed method when a button is clicked. After the button is clicked a new window is opened that contains the report viewer javabean:

// Create a target window for the viewer
Window window = new JDialog(this, "Report Viewer");
window.setSize(Toolkit.getDefaultToolkit().getScreenSize());
window.addWindowListener(this);
 
// Create the connection to the report server
URLRenderData myConnection = new URLRenderData(reportListener.getUrlString()+
		"/?report=file:" + System.getProperty("user.dir") + '/' + reportFile.getText());
 
// Create the Report Viewer
SwingReportViewer viewer = new SwingReportViewer();
 
// Create the report view and set the connection to the report server
viewer.addNewReportView(myConnection);

After creation of new window and report viewer the following parameters needs to configured:

  • report name
  • parameters for the report that the report viewer is going to send as a request to the report engine.

An example for a request string looks like:

http://hostname:portnumber?report=file:C:/reports/reportfile.rpt&promptMyPrompt=123

The method getUrlString() from the class Listener determines the host name and the port number of the host on which the Java application is running. The method System.getProperty(“user.dir”) determines the working directory of the application. In this example the report is located in a subdirectory of this working directory. The text field is used to enter the report name and the parameters for the report. You can also use other components (e.g., other text components) to set the report name and the necessary parameters. Another example for setting the report name is to read it from a database where all locations of the reports are saved.

You can find the complete code for this sample in the file “sample.java” that is located in the directory “sample” of the i-net Clear Reports documentation.

This sample application is a simple example for a standalone application with i-net Clear Reports.

See Also:


i-net software strives to provide accurate product documentation. Please give us your feedback using the form below.
NOTE: This form is for documentation feedback only. For technical assistance, please send an email to clearreports@inetsoftware.de.

 

© Copyright 1996 - 2012, i-net software; All Rights Reserved.