Implementing the Part Viewer

The Part viewer works much the same way as the Page viewer—in fact, much of the code is exactly the same, except for the type of viewer object that is created. Listing 32.6 assumes that the report to be displayed has an initial report part defined in the report itself.

Listing 32.6. Viewing a Report Using the Report Part Viewer
//To create a Java report part viewer you need to instantiate a
//CrystalReportPartsViewer object:
CrystalReportPartsViewer viewer = new CrystalReportPartsViewer();

//Obtain a ReportSource object. Set the viewer's report source by calling its
//setReportSource method
viewer.setReportSource(reportSource);

//After you have created and initialized a Java report part viewer, you
//call its processHttpRequest method to launch it in a Web browser.
viewer.processHttpRequest(request, response, getServletContext(), null);

If a report part is not defined for a report, or if the default part needs to be overridden, Listing 32.7 provides code that can be used to manipulate the ReportParts collection. Figure 32.2 shows the output of this page being displayed in a Web browser.

Listing 32.7. Specifying Report Part Nodes
//To create a Java report part viewer you need to instantiate a
//CrystalReportPartsViewer object:
CrystalReportPartsViewer viewer = new CrystalReportPartsViewer();

//After you have created the CrystalReportPartsViewer object,
//you must specify the report parts that you want to display when the
//viewer is launched.  To specify the report parts that you want the
//viewer to display Create a ReportPartsDefinition object.
ReportPartsDefinition partsDefinition = new ReportPartsDefinition();

//Get the collection of ReportPartNodes that belong to the
//ReportPartsDefinition.
ReportPartNodes reportPartNodes = partsDefinition.getReportPartNodes();

//Create a corresponding ReportPartNode object for each report part that
//you would like the viewer to display. Add these objects to the
//ReportPartNodes collection. Part1 is being used here as the default
//Report Part to display
ReportPartNode node0 = new ReportPartNode();
node0.setName("Part1");
partsDefinition.getReportPartNodes().add(node0);

//Obtain a ReportSource object. Set the viewer's report source by calling
//its setReportSource method
viewer.setReportSource(reportSource);

//Call the viewer's setReportParts method, passing it the ReportPartsDefinition.
viewer.setReportParts(partsDefinition);

//After you have created and initialized a Java report part viewer,
//you call its processHttpRequest method to launch it in a Web browser.
viewer.processHttpRequest(request, response, getServletContext(), null) ;
					

Figure 32.2. The Report Part viewer displaying a report part.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.205.99