JReport Result Viewer Bean Usage

The JReport Result Viewer Bean JRResultViewer is used to view the JReport  result file generated by the JReport Engine.  (The JReport Engine could be called in three different ways: by the JReport Worokbench, by the JReport Server, or by the JReport Engine Bean.) 

Installation

JReport Result Viewer Installation

JReport Result Viewer Bean is presently available as a zip file jrbean.zip that contains the 3  following  components:

The first step is to download the jrbean.zip file from the web:

http://www.jinfonet.com/jrbean_download.htm

These files may be unzipped into any directory or your choice.  The following sections give further details about the JReport Result Viewer Bean.

JReport Express Result Viewer Installation

JReport Express Result Viewer Bean is packed inside the JReport Express Edition package. After the installation of JReport Express Edtion, there are two JReport Express Result Viewer Bean files under the %installroot%\lib directory. These files are:

JReport Result Viewer Bean Properties

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

The ReportName specifies the name of the JReport result file to be viewed.  It contains both the path information and the file name.   vDebug, vError and vOff are used for showing debug and error information and how to turn off them.  LogFileName specifies where the debug, error and other information will go.  The LogFileName contains both the path and the file names.  If no path is specified, the current path is used;  If no file is specified, the file jreport.log is used.  'Yes/No' indicates whether to start to view the result of the report (the file specified by ReportName).

There are also three methods with which the JReport Result Bean will export result file(with the .rst extension) to different file formats(.htm, .pdf, .txt):

The parameters above are explained below:

Note: All the above export methods are not available in JReport Express Result Viewer.

Printing Reports

There are three methods provided for printing the report:

The first method printReport ( ) is called to start printing.  The second method allows you to pass the print job, page format and interactive operation.  After the printing is started, the method getPrintStatus ( ) can be used to get the print job status.  The return values of getPrintStatus ( ) are:

Browsing Report Pages

The following methods are also available to the JReport Result Viewer Bean (the  same as in the JReport Viewer Beans). 

These two methods will return the current page number and the total number of pages of the current report onto the screen.

This method will display the page specified by the PageNumber on the screen. If the PageNumber is out of the range of the current report, the first page (if the pageNumber is less than 0) or the last page will be shown on the screen and the return value is the current page number.

These four methods will bring the page specified to the screen.  The return value of these methods is a string.  The value could be:

Exit the Bean

There is a method called exit ( ) which should be called when you want to quit from the JReport Result Viewer Bean.  This method will do some cleaning up work such as deleting temporary files.  It is important not to forget to call this method!

Illustrative Example

1. TestResultBean.java

There is an example program called TestResultBean.java included in the JReport Result Bean package.  Please refer to it for more programming details.

2. TestJrxResultViewerBean.java

TestJrxResultViewerBean.java shows you how to use the methods provided by JReport express result viewer which we mentioned above, and explains how it works step by step. First TestJrxResultViewerBean.java contains some hard-coded paths.  These must be modified before they can be compiled and run.  For example, the following paths need to be changed:

1)You should change global variable for the example file.

String homePath = "c:\\jrexpress"; //Set the root that JReport Express be installed.
String reportPath = homePath + "\\Demo\\reports\\interbase\\";//Set the path that current report exists.
String resultPath = homePath + "\\temp\\";//Set the path for result files.

2)Change the following paths for the "Start" section. It mainly tells you how to make the report engine run.

bean.setReportName(resultPath + "formleter.rst");

Please see EngineBeanUsage.htm for more information about Jreport Express Engine Bean.

To run the TestJrxResultViewerBean.java, you can use the following commands to compile the test program:

javac -classpath d:\java\jre\lib\rt.jar;c:\jrexpress\lib\JRXShare.zip;c:\jrexpress\lib\JRXViewer.zip;c:\jrexpress\lib\JRXEngine.zip;c:\Jbuilder3\lib\swingall.jar;   TestJrxResultViewerBean.java

Here we still assume c:\JRExpress is the place where the JReport Express Result Viewer is installed and it is the current directory when you execute these commands. If you run the report for interbase user, you must add classpath "C:\Program Files\InterBase Corp\InterClient\interclient.jar", or delete it from classpath. Finally the test program can be run with the following commands:

java -Djava.compiler=NONE -classpath d:\java\jre\lib\rt.jar;c:\jrexpress\lib\JRXShare.zip;c:\jrexpress\lib\JRXViewer.zip;c:\jrexpress\lib\JRXEngine.zip;c:\jrexpress\lib\resource.zip;c:\Jbuilder3\lib\swingall.jar;"C:\Program Files\InterBase Corp\InterClient\interclient.jar"; TestJrxResultViewerBean