Implementing the Part Viewer


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

Listing 33.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 33.7 provides code that can be used to manipulate the ReportParts collection. Figure 33.2 shows the output of this page being displayed in a web browser.

Listing 33.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 33.2. The Report Part viewer displaying a report part.





Crystal Reports XI(c) Official Guide
Crystal Reports XI Official Guide
ISBN: 0672329174
EAN: 2147483647
Year: N/A
Pages: 365

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net