BackPrevious Page Next PageNext

JReport Result Viewer Bean

Installing the Result Viewer Bean

Result Viewer Bean properties

Preparations before using the Result Viewer Bean

Using the Result Viewer Bean

Exporting report result to different file formats

Printing report result

Browsing report pages

Zooming report pages

Getting report page orientation

Getting field results by listening to the click event

Setting the report communicator

Setting the user input stream

Result Viewer Bean Sample

JReport Result Viewer Bean enables you to show the report result files (.rst extension), export the report result files to multiple file formats (HTML, PDF, XLS, RTF, Postscript, Text, CSV, E-mail) and to printer.

Installing the Result Viewer Bean

The Result Viewer Bean is available when you install JReport Designer. The following are the main components under the installation root that are required for using the Result Viewer Bean:

The components marked with * are must when you call the Result Viewer Bean. For other components you should add them to your class path to call the Result Viewer Bean depending on the use case. For example, when you want to use the Result Viewer Bean to export a result file to mail, you should add mail-1.4.7.jar and activation-1.1.1.jar with a valid path to your class path, and when you want to export the result file to XML, you should add resource_en_US.jar with a valid path to your class path.

Result Viewer Bean properties

JReport Result Viewer Bean has four properties: reportName, showInfoLevel, logFile and loadReport. The following methods are used to set the values of these properties:

Parameters

Preparations before using the Result Viewer Bean

Before programming with the Result Viewer Bean, you need to import the classes of the Result Viewer Bean by adding the following import statements to the beginning of your program. The first import statement is added to import the bean class:

import jet.bean.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

Then, you need to create an instance.

To run with the Result Viewer Bean, you should first create an instance of it. The constructor of the Result Viewer Bean has no parameter. After the object has been created, you should then set the report name and temp path (if not set, the current path will be used).

bean = new JRResultViewer();
bean.setShowInfoLevel(bean.vDebug | bean.vError);
bean.setReportName("c:\\test\\customerlist.rst");
bean.runReport("yes");

With the Result Viewer Bean object, you can show the report result and export it to other formats or to printer. You do not need to create a bean for each report.

Using the Result Viewer Bean

JReport Result Viewer can be used to view local JReport result files generated by the JReport Engine. You can show the report result file ( .rst) and export the report result to multiple file formats and to printer by calling the Result Viewer Bean.

Note that after finishing using the Result Viewer Bean, you need to call the method exit() to quit from it. This will perform some clean up work, such as deleting temporary files. It is important to free up the resources of the result file, so remember to call this method.

Reference: For more information about the Result Viewer Bean, see also the JReport Javadoc jet.bean.JRResultViewer class in <install_root>\help\api.

Exporting report result to different file formats

There are several methods with which JReport Result Bean can export a result file (.rst extension) to different file formats (.htm, .pdf, .txt, and so on):

Parameters

Notes:

Printing report result

There are five methods provided for printing the report result.

Parameters

Example 1

With JDK1.2 or later, if you use the JDK1.2 printing method (boolean bUseJDK11), you can call the printReport method as shown below:

PrinterJob printJob=PrinterJob.getPrinterJob();
bean.printReport(printJob, printJob.defaultPage(), false, false, false);

Or, if you do not want to use getPrinterJob, you can simply call:

bean.printReport(null, null, false, false, false);

Example 2

With JDK1.2 or later, if you use the JDK1.1 printing method, you are best recommended not to use getPrintJob, instead you can call:

bean.printReport(null, null, false, false, true);

Notes:

Browsing report pages

You can use the following methods to browse the report pages:

The return value of the above methods is a string, and can be: "OK", "No more page" or other error messages such as "No report load".

Zooming report pages

If you want to zoom in or out of the report pages, there is a method named zoom(ratio) that will meet this requirement.

Parameter

For example, if you want to enlarge the report pages by two times the original size, you can use the method in this way: zoom(200)

To reduce the report size by half, use the method in this way: zoom(50)

Getting report page orientation

To get the orientation of the report pages, use the method getPageOrientation(). You should call this method after calling the runReport method. The return value is an int value, and can be LANDSCAPE or PORTRAIT. If it is -1, it makes no sense, and is incorrect. For example, you may have called it before calling runReport method.

Getting field results by listening to the click event

When you click a field in the viewer, you can get the entire record of the field. The interface in package jet.thinviewer named ClickActionListener can implement this function. This interface is defined as:

interface ClickActionListener 
{
	void clickOnField(jet.connect.Record currentRecord);
}

If you have a class which wants to listen to the click event of a field, this class can implement this interface. Then, after you have instantiated a bean, you can add the ClickActionListener.

Note: This action must be implemented before running the report. Finally after the report has been shown and you click on a field, the ClickActionListener's method clickOnField will be called, and you will then get the values of all columns in that field from the parameter currentRecord.

Setting the report communicator

The method SetReportCommunicator(Communicator) is used to set the report communicator.

Parameter

Setting the user input stream

To view the result file with the Result Viewer Bean, you usually set the report name to a physical .rst file. If you want to set the stream of the .rst file, you can use the method below:

setInputStream(InputStream ins, boolean zip)

Parameters

Result Viewer Bean sample

There is a sample program called TestResultBean.java in <install_root>\help\samples\APIViewResult.

The properties for the report are very simple, and you will only need to set the ReportName. Note that here the report name is the report result .rst file generated by the JReport Engine. It is not a .cls file. By calling the runReport and show() methods, the report result will be displayed.

The report result can be exported to other formats such as HTML, PDF, RTF or to a printer. You will need to use the appropriate methods and parameters.

To run TestResultBean.java, you can use the following command to compile the sample program first (assume that JReport Designer has been installed to C:\JReport\Designer):

C:\JReport\Designer\help\samples\APIViewResult>javac -classpath "C:\JReport\Designer\lib\JREngine.jar;C:\JReport\Designer\lib\log4j-core-2.10.0.jar;C:\JReport\Designer\lib\log4j-api-2.10.0.jar" TestResultBean.java

BackPrevious Page Next PageNext