Implementing the Page Viewer
The first viewer component to be covered is the Page viewer, as illustrated in Listing 32.5. To use this viewer, you will create its CrystalReportViewer object. It, along with all the other viewers, exposes a method called setReportSource that accepts a valid report source object as obtained from the description in the previous section. Finally, again like the other viewers, it has a processHttpRequest method that accepts references to the current servlet context. This method does the actual rendering to HTML.
Listing 32.5. Viewing a Report over the Web
//To create a Java report viewer you need to instantiate a CrystalReportViewer //object. To create a CrystalReportViewer object: CrystalReportPartsViewer viewer = new CrystalReportViewer(); //Obtain a ReportSource object. Set the viewers report source by calling its //setReportSource method. viewer.setReportSource(reportSource); //When you have created and initialized a Java report page viewer, you call //its processHttpRequest method to launch it in a Web //browser. viewer.processHttpRequest(request, response, getServletContext(), null);
Figure 32.1 shows the output of this code.
Figure 32.1. A report being displayed in an HTML page viewer.
All viewers including the Page viewer share a number of toolbar elements. These properties can be programmatically toggled and are displayed in Table 32.1. All the viewer properties must be set before calling the ProcessHTTPRequest method that displays the selected report. For example, to ensure the Crystal logo is displayed when the involved report is viewed, the code line
Viewer.HasLogo(true);
needs to be included in the code before the processHTTPRequest method is called.
As the different viewers are introduced and discussed later in this chapter, some additional elements pertinent to the viewer being discussed will be displayed in that sections table.
Категории