2.) Introduction to Page Viewer
The Report Viewer component offers users the capability of viewing and manipulating a report through a Web browser. The viewer loads the report template on the client and shows it to the user with the latest data. Report Viewer, however, is not the ideal deployment solution when the report contains a large amount of data. In these situations, loading the entire report on the client would cause the client to quickly run out of memory.
For situations like this, EspressReport provides another viewer called Page Viewer. Instead of loading the entire report on the client, Page Viewer employs a page serving technology that allows the client to load only one page of the report at a time. This allows the report to load faster, and conserve the client memory.
Page Viewer works by exporting the report into a series of page (.page) files that contain the drawing information for a set of pages in the report. The .page files are then loaded in the viewer on the client. Users running with EspressManager, can directly pass in a report template as part of Page Viewer code. The report will be exported on the server with the latest data, and the client will load the .page files. Users running without EspressManager can export the report in "view" format either from the API or Report Designer. These exported files can be loaded directly in Page Viewer without the EspressManager.
To launch Page Viewer, you can embed the Viewer in an applet using a .rpt file (EspressManager) or an exported view (.view) file (With or without EspressManager). Page Viewer can also be used to load a report directly from the Preview window in Report Designer.
To embed Page Viewer in an applet, simply use the following code:
<applet codebase = ".." code = "quadbase.reportdesigner.PageViewer.Viewer.class" width = 100% height = 100% archive="PageViewer.jar">
<PARAM name = "filename" value = "yourReport.rpt">
</applet>
The parameter value of "filename" specifies the name of the file that contains the report. If you're running Page Viewer with EspressManager on the back-end you can specify the name of a report template. You can also use an exported view file for this parameter. When using a view file with Page Viewer, you do not have to have EspressManager running. The filename value can also be specified by a URL; for example, you can prefix it by http:// for accessing a remote data file.
You may also use Page Viewer in an application, simply use the following code to get a java.awt.Component Object.
quadbase.reportdesigner.PageViewer.Viewer.getComponent(java.awt.Frame frame, java.lang.String fileName, long bufferTimeInSec)
In addition to passing in the template file (or view file), you can also pass in a QbReport object. Note that instead of using the Viewer class, you would be using the ViewerAPI class.
quadbase.reportdesigner.PageViewer.ViewerAPI.getComponent(java.awt.Frame frame, QbReport report, long bufferTimeInSec, java.lang.String securityLevel);
The above methods are the simpliest of all methods for getting Page Viewer as a Component. For more information about the parameters for this constructor or information on other methods related to Page Viewer, please consult the EspressReport API Specification.
Note that on the server side, you will need to copy the PageViewer.jar file from the lib/ directory of the EspressReport Installation to some directory of your web server that is accessible by the web client.
2.2.1.) Launching from Report Designer
Page Viewer can also be invoked from Report Designer. When previewing a report with a large amount of data, the report can be loaded in a Page Viewer window. This allows users to preview/view the entire report without loading all the data in memory. For more information about this feature, please see section 6.2.4 of the Designer Guide.
2.3.) The Page Viewer Parameters
Without using Report Designer, you can also pass data via parameters to Page Viewer applet. That is, you can use Page Viewer to directly view a data file, or pass the data directly in the form of lines of data, in the HTML code. The following is a list of parameters:
Page Parameters
Example: With the parameter BufferTime you can insert the following line:
<PARAM name="BufferTime" value="3600">
In the above example, when Page Viewer applet opens, it will fetch data from the specified data source (with the help of EspressManager) if more than 1 hour (3600 seconds) has passed since the local existing .page file has been updated. Otherwise Page Viewer will display the local existing .page file, if it exist. If it doesn't exist, it also fetches data from the specified data source.
Note that when specifying color parameters Use the Hexadecimal format for RGB colors that is standard in HTML tags. That means the first two hexadecimal digits are for Red, the next two are for green, the last two are for blue. A total of six hexadecimal digits has to be specified for a color. For example,
<PARAM name="DataHintBgColor" value="ff00aa">
Using Page Viewer, you can browse through the pages of the report using the Pop-Up Menu. Right clicking on the report displays a Pop-Up Menu which can be used to traverse the report. The Pop-Up Menu shows the various options:
In addition to the Pop-Up Menu, you can also
A problem working with the view (.view) and page (.page) files associated with Page Viewer is that while saving memory and boosting performance by caching the report page by page on a file system, Page Viewer files' data might become obsolete in time. In other words, they might not reflect the latest report data. The solution to this is to have a mechanism for updating the Page Viewer files during certain time intervals.
Page Viewer provides the mechanism to adjust the time elapsed until a new view file needs to be fetched from the server. This time interval, also known as the Buffer Time, can be adjusted by setting the parameter BufferTime in Page Viewer applet. Simply pass in the buffer time in seconds as the value to the parameter BufferTime. The Page Viewer will then fetch new pages whenever the current version of the VIEW file becomes older than the specified buffer time.
Also, Page Viewer has a built-in mechanism that automatically eliminates old view and page files when they have not been updated for 3 days or more.
2.6.) Connecting to EspressManager
2.6.1.) EspressManager running as application
EspressManager is run primarily as an application. If you wish to use Page Viewer to connect to EspressManager running an application, you will have to add the following tags to your HTML code:
<PARAM name="server_address" value="someMachine">
<PARAM name="server_port_number" value="somePortNumber">
Adding the above params to your HTML code will make Viewer connect to EspressManager running on someMachine and listening on somePortNumber.
2.6.2.) EspressManager running as servlet
EspressManager can be run as a servlet as well. If you wish to use Page Viewer to connect to EspressManager running as servlet, you will have to add the following tags to your HTML code:
<PARAM name="comm_protocol" value="servlet">
<PARAM name="comm_url" value="http://someMachine:somePortNumber">
<PARAM name="servlet_context" value="EspressReport/servlet">
Adding the above params to your HTML code will make Viewer connect to EspressManager at http://someMachine:somePortNumber/EspressReport/servlet.
A JFC/Swing version of the Page Viewer can also be used to referring to SwingPageViewer.jar instead of PageViewer.jar in the EspressReport/lib directory.
This section pertains to exporting from the viewer in an Applet only. When using the Page Viewer API to create a Component that displays a report, the user can right-click on the Component to launch a pop-up menu with various options. One of the options (Output->Server->Generate...) is for exporting the report to different file formats. This will result in creating the exported file on the server side. However, there is an API feature that utilizes a server-side Java Servlet to stream back the exported content to the client's browser. The following describes how to use this feature.
First, you need to deploy the Servlet that will stream the exported file back to the client side needs to be deployed. This servlet, called ViewerExportServlet, is located at <espress-report-install-dir>/ViewerExport/ViewerExportServlet.java. Simply compile the Servlet and deploy it in your Servlet container.
Next, in the code that retrieves the report Component, four lines of code need to be added:
Viewer viewer = new quadbase.reportdesigner.PageViewer.Viewer();
Component comp = viewer.getComponent((Applet)null, reportTemplate, 0);
viewer.setExportServlet("http://host:port/servlet/ViewerExportServlet");
viewer.setDynamicExport(true, "host", port, "servlet/");
where reportTemplate is a string containing the name and path of the report template file. You can also pass in a QbReport object using the following code:
ViewerAPI viewer = new quadbase.reportdesigner.PageViewer.ViewerAPI();
Component comp = viewer.getComponent((Applet)null, report, 0, null);
viewer.setExportServlet("http://host:port/servlet/ViewerExportServlet");
viewer.setDynamicExport(true, "host", port, "servlet/");
where report is a QbReport object.
The argument for the setExportServlet method is the url location of your deployed ViewerExportServlet. Please see the javadoc Specification for more details about the arguments of these two methods.
Then, when the user views the report Component, there will be new options under Output->Client->(Generate...). All of these options will result in a pop-up browser window that contains the streamed content of the report.