JReport Viewer Bean Usage

In order to make the Viewer easily embedded in user's Java applications, the JReport Viewer is now also available as a Java Bean.  The JReport Viewer Bean can send a request from a client workstation to run and view reports on the JReport Server.

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

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

There are 5 files inside  jvbean.zip:

The two approaches of invoking the JReport Viewer Bean are described in the following sections. 

Invoking Viewer Bean without Supplying Report Parameters

In this approach, your Java applications calls the Java bean JRDirectViewer and provides the following properties:

After the Java bean JRDirectViewer is loaded, it will ask the JReport Server to run the report and will pop up a dialog on the screen to ask the user to input report parameters if they are required by the report. This approach has the advantage of not requiring the user Java application to provide the report parameters. The disadvantage is that it will display a dialog on the screen for the user to enter parameters.

Invoking Viewer Bean with Report Parameters

The second approach of invoking the JReport Viewer Java Bean has two passes: the first pass obtains information about the parameters required by the report and the second pass submits the required parameters.  If the user Java application has already known the required parameters,  the first pass may be eliminated.   In this approach, the Viewer Java Bean will not display any dialog on the screen.   The user Java application retains the full control to the screen.   User Java application is responsible for submitting all the required report parameters.

Pass one:

The user Java application calls the Java bean JRPrepareViewer with the following properties:

JRPrepareViewer returns a vector containing the information about the report.  The method getReportParams ( ) should be called after calling JRPrepareViewer to obtain the vector. The size of the vector is the number of the parameters needed by the report, which can be obtained from the method size ( ).  Each element in the vector contains the type of a parameter, which can be obtained using the method getType ( ). The possible parameter types are listed below:

Pass two:

In the second pass, the user Java application prepares the parameters based on the information provided by the vector.Then It  calls the Java bean JRRunViewer with the following properties:

Note: Parameters -- The string containing the parameter values, separated by comma (','). If there are more than one parameters needed in the report, you can pass multiple parameters in the Parameters string.  The format is: paraName1=paraValues1,paraName2=paraValue2 where the paraName1 and paraName2 are the parameter names and paraValue1 and paraValue2 are the values.e.g. ("204,177,.148,110")

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

The parameters above are explained below:

Also JReport Viewer Bean provides the methods to add, delete, save and get a new WHERE clause in the SQL query(we will provide the last three methods in the future).  By specifying the name of this new WHERE clause,  users can pick it out from the report catalog easily:

The parameters above are explained below:

Return Codes, Printing Reports, and Browsing Pages

Check Return Codes

The first method getStatus ( ) should be called each time after calling the Viewer Java Beans.  The return string "OK" means the request is accepted otherwise an error message is returned.

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 only available to the JReport Viewer Beans build 50 or later.  To find out the build number of your JReport Viewer Bean, please refer to the readme file in the package.  If  you  cannot   find the readme  file, it  is highly recommended to         re-download the JReport Viewer Bean package from our web .

These two methods will return the current page number on the screen and the total number of pages of the current report.   These two methods can be called only after you have called the method JRDirectViewer or JRRunViewer.

This method will bring 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 retune value of these method is a string.  The value could be:

Show information

The two properties showInfoLevel and logFile are used for controlling debug, error and other information display.  The following two methods are used to set the values to these properties:

vDebug, vError and vOff are used for showing debugging information, error information and turning off debugging and error information.  LogFileName specifies where the debugging, error and other information will go.  LogFileName contains both path and file name information.  If no path is specified, the current path is used.  If no file name is specified, the file jreport.log is used.

Exiting the Bean

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

Illustrative Examples

The example program Sample1.java, Sample2.java and Sample3.java show you how to call JReport Viewer Java beans. Please refer to it for details.