Interactive Viewer


In the preceding section, you learned how to specify selection criteria within your JSP application to display parts of a report. This is fine if you know which parts the user of your JSP application requires. However, you ll come across some users who aren t sure what parts they need. In these situations, it is best to make use of the Interactive Viewer.

The Interactive Viewer enables the user of the report to perform a subquery from a list of fields on the initially viewed report consisting of the list of desired report fields, as well as selection criteria to further narrow down report data. You ll need to create JSP code to display the report in the Interactive Viewer. The Interactive Viewer can be used as a standard viewer. The Advanced Search control is an optional portion of the Interactive Viewer. The report will still be displayed by using the Interactive Viewer even if you deactivate the Advanced Search control.

Note  

The Interactive Viewer is an optional viewer that provides the additional query capabilities. It is not required for use with the Java Reporting Component. In fact, it is only available if your Java application uses a ReportClientDocument report source from a Report Application Server.

Begin by creating an instance of the CrystalReportInteractiveViewer class and setting the report source, as shown here:

 CrystalReportInteractiveViewer viewer = new CrystalReportInteractiveViewer(); 
viewer.setReportSource(reportSource);

You ll need to activate features that will be made available to the user of your JSP application. The first feature that you must address is the default formula that is used with the Advanced Search Control. The Advanced Search Control is a dialog box that enables the user to enter complex search criteria used to select data for the report. The country of the customer is set by using the setAdvSearchFormula, as shown here:

 viewer.setAdvSearchFormula("{Customer.Country}=\"Japan\""); 

You should also include a list of report fields in the Advanced Search Control so that the user of your JSP application can choose the fields that will appear on the report. Fields are contained in a String array and displayed by calling the setAdvSearchShowFields() method, as illustrated in the following statements:

 String fieldNames[] = new String[1] ; 
fieldNames[0] = "Customer.Customer Name";
viewer.setAdvSearchShowFields(fieldNames);

This code is an example and not a requirement. If you remove this code, the user of your JSP application will be required to enter the data when your application executes.

The final three steps are to activate the Fields tab and the Conditions tab on the Advanced Search Control and then to display the interactive viewer. The Fields tab is used to choose fields that appear in the report, and the Conditions tab enables the user to enter the condition for selecting data for the report. These tabs are activated by passing the appropriate method a Boolean value of true, which is shown next . Once you ve activated these tabs, you can display the interactive viewer by calling the processHttpRequest() method, which is also illustrated here. Figure 23-2 shows you the screen generated by this program.

click to expand
Figure 23-2: Advanced Search Control of the Interactive Viewer
 viewer.setShowAdvSearchFieldsTab(true); 
viewer.setShowAdvSearchConditionsTab(true);
viewer.processHttpRequest(request, response,
getServletConfig().getServletContext(), null);

The following is the completed JSP application that displays the interactive viewer:

 <%@ page import= 
"com.crystaldecisions.report.web.viewer.CrystalReportInteractiveViewer"%>
<%
CrystalReportInteractiveViewer viewer = new CrystalReportInteractiveViewer();
viewer.setReportSource(reportSource);
viewer.setAdvSearchFormula("{Customer.Country}=\"Japan\"");
String fieldNames[] = new String[1] ;
fieldNames[0] = "Customer.Customer Name";
viewer.setAdvSearchShowFields(fieldNames);
viewer.setShowAdvSearchFieldsTab(true);
viewer.setShowAdvSearchConditionsTab(true);
viewer.processHttpRequest(request, response,
getServletConfig().getServletContext(), null);
%>



Crystal Reports 10
Crystal Reports 10: The Complete Reference
ISBN: B005DI80VA
EAN: N/A
Year: 2004
Pages: 223
Authors: George Peck

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