Previous Page Next Page
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:
- lib\log4j-core-2.10.0.jar*;lib\log4j-api-2.10.0.jar*
Jar file used for the JReport Engine logging system.
- lib\activation-1.1.1.jar
Jar file for exporting to mail.
- lib\mail-1.4.7.jar
Jar file for exporting to mail.
- lib\resource_en_US.jar
Archive file used when exporting to XML.
- lib\poi-3.15.jar
Jar file used when exporting to Excel.
- SwingDesigner.jar
If RPTExecutor UDO has been inserted into a report, to view the correct result, this jar file should be added to the class path that starts 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:
- setReportName ("ReportName")
- setTempPath("theTemporaryPath");
- setShowInfoLevel (vDebug/vError/vOff)
- setLogFile ("LogFileName")
- setLoadReport ("Yes/No")
Parameters
- ReportName - Specifies the name of the JReport result file that is to be viewed. It contains both the path information and the file name.
Note: Here the report name is the result file name with an .rst extension (NOT the report file .cls).
- theTemporaryPath - The temporary file path. When the bean runs, the temporary files will be written in this path. You should set the full path of the temporary files in this method as:
bean.setTempPath("c:\\temp");
If you do not set the temporary path, the default path is the directory from where the Bean will be run.
- vDebug/vError/vOff - These are used for showing and turning off debug and error information. LogFileName specifies where the debug, error and other information will go. LogFileName contains both the path and the file name. If no path or file is specified, the default will be used.
- Yes/No - Indicates whether or not to start to view the result of the report (the file specified by ReportName).
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):
- Export to HTML
- exportToHtml(string HTMLFileName)
- exportToHtml(string HTMLFileName, HtmlParameter Parameter)
- exportToHtml(string HTMLFileName, boolean bChartApplet, boolean isMultiFile, boolean bUsingTable, boolean bHyperlink, boolean bPageNum, boolean Absolute, int iBrowser)
- exportToHtml(string HTMLFileName, boolean bChartApplet, boolean isMultiFile, boolean bUsingTable, boolean bHyperlink, boolean bPageNum, boolean bAbsolute, int iBrowser, Drilldownfile)
- exportToHtml(string RSTFileName, string HTMLFileName, boolean bChartApplet, boolean isMultiFile, boolean UsingTable, boolean Hyperlink, boolean PageNum, boolean bAbsolute, int iBrowser, boolean bincdrilldownfile, boolean noMargin)
- exportToHtml(string rstFileName, string HTMLFileName,
boolean bChartApplet, boolean isMultiFile, boolean bUsingTable,
boolean bHyperlink, boolean bPageNum,
boolean bAbsolute, int iBrowser, boolean bincdrilldownfile, boolean noMargin, int resolution)
- Export to Page Report Result
- exportToDhtml(string HTMLFileName)
- exportToDhtml(string RSTFileName, string HTMLFileName, boolean bChartApplet, boolean isMultiFile, boolean bUsingTable, boolean bHyperlink, boolean bPageNum, boolean bAbsolute, int iBrowser, boolean bincdrilldownfile, boolean noMargin)
- exportToDhtml(string HTMLFileName, boolean bChartApplet,
boolean isMultiFile, boolean bUsingTable, boolean bHyperlink,
boolean bPageNum, boolean bAbsolute, int iBrowser, boolean bincdrilldownfile,
boolean noMargin, int resolution)
- exportToDhtml(string HTMLFileName, boolean bChartApplet, boolean isMultiFile, boolean bUsingTable, boolean bHyperlink, boolean bPageNum, boolean bAbsolute, int iBrowser)
- exportToDhtml(string HTMLFileName, boolean bChartApplet, boolean isMultiFile, boolean bUsingTable, boolean bHyperlink, boolean bPageNum, boolean bAbsolute, int iBrowser, boolean bincdrilldownfile)
- exportToDhtml(string HTMLFileName, boolean bChartApplet, boolean isMultiFile, boolean bUsingTable, boolean bHyperlink, boolean bPageNum, boolean bAbsolute, int iBrowser, boolean bincdrilldownfile, boolean noMargin)
- Export to PDF
- exportToPdf(string PDFFileName)
- exportToPdf(string FileName, PDFParameter Parameter)
- exportToPdf(string PDFFileName, boolean noMargin)
- exportToPdf(string PDFFileName, boolean noMargin, boolean isSimPrintMode)
- exportToPdf(string PDFFileName, boolean noMargin, boolean isSimPrintMode, int isCompressImage)
- exportToPdf(string RSTFileName, string PDFFileName, boolean noMargin, boolean isPrintMode, int isCompressImage, boolean isTransparent)
- exportToPdf(string PDFFileName, boolean noMargin, boolean isSimPrintMode, int isCompressImage, boolean isTransparent, boolean bToc, boolean bDrill, string password)
- exportToPdf(string PDFFileName, boolean noMargin, boolean isSimPrintMode, int isCompressImage,
boolean isTransparent, boolean bToc, boolean bDrill)
- Export to Text
- exportToText(string TextFileName, boolean isNormalText)
- exportToText(string TextFileName, TextParameter Parameter)
- exportToText(string TextFileName, boolean isNormalText, int udchWidth, int unchHeight)
- exportToText(string TextFileName, boolean isNormalText, boolean isRepeat, char delimiter)
- exportToText(string TextFileName, boolean isNormalText, boolean isRepeat, char delimiter, boolean compress)
- exportToText(string TextFileName, boolean isNormalText, boolean isRepeat, char delimiter, boolean compress, boolean quoteMark)
- exportToText(string TextFileName, boolean isNormalText, boolean isRepeat,
char delimiter, int udchWidth, int udchHeight, boolean compress, int resolution, boolean quoteMark, boolean hasHeadfoot)
- exportToText(string TextFileName, boolean isNormalText, boolean isRepeat, char delimiter,
int udchWidth, int udchHeight, boolean compress, int resolution, boolean quoteMark,
boolean hasHeadfoot, boolean forWindows)
- exportToText(string TextFileName, boolean isNormalText, int udchWidth, int udchHeight, boolean compress, int resolution)
- exportToText(string TextFileName, boolean isNormalText, int udchWidth, int udchHeight,
boolean compress, int resolution, boolean quoteMark)
- Export to Excel
- exportToXls(string XLSFileName)
- exportToXls(string XLSFileName, ExcelParameter Parameter)
- exportToXls(string XLSFileName, int isWordWrap)
- exportToXls(string XLSFileName, int isWordWrap, boolean isBiff8)
- exportToXls(string XLSFileName, int isWordWrap, boolean isBiff8, int param)
- Export to PS
- exportToPS(string PSFileName)
- exportToPS(string PSFileName, boolean noMargin)
- exportToPS(string PSFileName, PSParameter Parameter)
- Export to RTF
- exportToRtf(string RTFFileName)
- exportToRtf(string RTFFileName, boolean noMargin)
- exportToRtf(string RTFFileName, RTFParameter Parameter)
- Export to XML
- exportToXML(string XMLlFileName, boolean isMultiFile, boolean isOnlyData)
- exportToXML(string XMLFileName, boolean isDataOnly, string xsdFile)
- exportToXML(string XMLFileName, boolean isDataOnly)
Parameters
- HTMLFileName - The name of the HTML format result file with a full path.
- bChartApplet - A boolean value which specifies whether or not the chart in an HTML file is an applet. The default value is false. This parameter is deprecated and not recommended to use.
- isMultiFile - A boolean value which specifies whether or not HTML is generated to a single file or to multiple files. The default value is true.
- bUsingTable - A boolean value which specifies whether or not to use HTML table format when exporting HTML files. The default value is false.
- bHyperLink - A boolean value which specifies whether or not a hyperlink is generated. The default value is true.
- bPageNum - A boolean value which specifies whether or not to generate page numbers. The default value is true.
- bAbsolute - A boolean value which specifies whether the font size is absolute or relative. The default value is true.
- iBrowser - An int value which specifies whether or not the web browser is IE. 0 means IE. The default value is 0.
- Drilldownfile - A boolean value which specifies whether or not to generate the drilldown HTML files in the file list. The default value is false.
- RSTFileName - The name of the result file (.rst extension) that is to be converted to the required format.
- PDFFileName - The name of the PDF format result file with a full path.
- isSimPrintMode - A boolean value which specifies whether or not to use Simulated Printing Mode (true) or Standard Mode (false) (To PDF). By checking the Standard Mode, the exporting speed will be much improved. The default value is false.
- isCompressImage - An int value which specifies the compression ratio of the image in a report (To PDF). The values range from 1 to 100. The default value is 20.
- isTransparent - A boolean value which specifies whether or not to keep the background of the GIF image transparent.
- TextFileName - The name of the Text format result file with a full path. true/false is to set whether this text file is in normal Text format or standard Data format. The standard Data format text file is a text file where each row represents a single record in the report. It can be used as a text datasource for exchanging data with other applications.
- isNormalText - A boolean value which specifies whether or not the text file is in normal text format. When it is set to false, the output format is in standard data format. The default value is true.
- isRepeat - A boolean value which specifies whether or not the same contents are repeated. The default value is false.
- delimiter - A character used in SDF (Standard Data Format) format. The delimiter will only be used when the "isNormalText" parameter is set to false. The default delimiter is a blank space.
- compress - A boolean value which specifies whether or not to remove empty lines or redundant delimiters in the exported text file. The default value is false.
- XLSFileName - The name of the Excel format report result file with a full path.
- PSFileName - The name of the Postscript format result file with a full path.
- RTFFileName - The name of the Rich Text Format file with a full path.
- noMargin - A boolean value which specifies whether or not to generate a file without a page margin. The default value is false.
- chWidth - User defined char width used in plain text format. It would be ignored if the value is 0 or less than 0. When exporting to Text, the default value is -1.
- chHeight - User defined char height which is used in plain text format. It would be ignored if the value is 0 or less than 0. When exporting to Text, the default value is -1.
- XMLFileName - The XML file name.
- isMultiFile - A boolean value which specifies whether XML is generated to a single file or to multiple files.
- isOnlyData - A boolean value which specifies whether or not only the database column information is exported to an XML file. Otherwise, all the report details, including all the properties will be exported. The default value is false.
- parameter - A parameter contains some special settings for exporting to different file formats.
- resolution - An int value which is used to specify resolution for different exported file formats.
- password - A string value which is used to set the password when exporting to a PDF file that contains a password.
- bToc - A boolean value which specifies whether or not to generate TOC for the PDF file.
- bDrill - A boolean value which specifies whether or not to apply drill-down function to the exported PDF file.
- quoteMark - A boolean value specifies whether or not quote characters will be kept in standard format text file.
- hasHeadfoot - A boolean value specifies whether or not page header and footer will be contained when exporting to TEXT.
- forWindows - A boolean value specifies whether the CR-LF in Windows convention or the LF in Unix convertion will be used as the end-of-line character.
- udchWidth - An int value which is specified for each unit of the horizontal density between columns.
- udchHeight - An int value which is specified for each unit of the vertical density between columns.
- isWordWrap - An int value which specifies a word wrap setting option.
- KEEPORIGIN - Keeps all the original settings of each component's Word Wrap property as specified in the report.
- NOWORDWRAP - Disables the Word Wrap property for all components.
- WORDWRAPALL - Enables the Word Wrap property for all components.
- isBiff8 - A boolean value specifies whether or not to export reports to a Data Format file, which means only the report data will be exported without format.
- param - An int value specifies whether or not to include drawing objects in the exported Excel file. If isBiff8 is set to true, drawing objects will not be included in the result file, because they cannot be exported to Data Format files, which means only the report data will be exported without format.
- NOEXPORTSHAPE - Drawing objects will not be exported to Excel files.
- EXPORTSHAPE - Drawing objects will be exported to Excel files.
- XSDFile - A string value indicates the schema file on which the exported XML file is based. If it is set to null, a new XSD file will be output.
Notes:
- Method exportToHtml(string HtmlFileName) will use the method exportToHtml(string HTMLFileName, boolean bChartApplet, boolean isMultiFile, boolean bUsingTable, boolean bHyperlink, boolean bPageNum, boolean bAbsolute, int iBrowser) using default parameter values, such as: exportToHtml("HtmlFileName", false, true, false, true, true, true, JRResultViewer.IE).
- Method exportToText(string TextFileName, boolean isNormalText) will use the method exportToText(string TextFileName, boolean isNormalText, boolean isRepeat, char delimiter) using default parameter values such as: exportToText( "TextFileName", isNormalText, false, ' ').
Printing report result
There are five methods provided for printing the report result.
- printReport()
- printReport(Object printJob, Object pageFormat, boolean bInteractive, boolean bInBackground, boolean bUseJDK11)
- printReport(Object printJob, Object pageFormat, boolean bInteractive, boolean bInBackground, boolean bUseJDK11, boolean bSeparateLargePage)
- printReport(java.lang.Object job, boolean bInteractive, java.lang.Object pf, boolean bInBackground, JReportPrintListener jreportprintlistener, int useJDK, java.lang.String jobName, java.util.Vector attributeInfo, java.lang.String printer)
- getPrintStatus()
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:
- The first method printReport() is called to start printing. It will take the third method using default parameter values such as:
printReport(null, null, true, false, false, false)
- The second and third method allows you to pass the parameters - printJob, pageFormat, bInteractive, bInbackground, bUseJDK11 and bSeparateLargePage.
- The third printing method (with the bSeparateLargePage parameter) is not recommended. It may cause some unexpected errors, for example, you may get an extra blank page.
- After printing has started, the method getPrintStatus() can be used to get the print job status. Returned values of getPrintStatus() are:
"No print job"
"Busy"
"OK"
"No report load"
Other error messages if there are errors.
Browsing report pages
You can use the following methods to browse the report pages:
- The methods getCurrentPageNumber() and getTotalPageNumber() are used to return the current page number and the total number of pages of the current report onto the screen.
- The method int gotoPage(int pageNumber) is used to display the page specified by PageNumber on the screen. If 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 screen. The returned value is the current page number.
- The methods firstPage(), prevPage(), nextPage() and lastPage() are used to show the specified page on the screen.
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
- ratio - Integer type, representing a percentage value.
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
- communicator - The Communicator here is a class defined by JReport. After users set the communicator, the viewer will load the report from this communicator, not the result file.
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
- ins - The user input stream.
- zip - Whether the result is compressed or not. To see whether the result is compressed or not, you can call the method: boolean isZipStream(InputStream ins).
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
Previous Page Next Page