Example 1 - Set Parameters

The following example is a JSP page that demonstrates how to set a parameter field for a report containing a Country parameter. After the parameters have been set, the report is displayed.

Note:    For any report used with this tutorial sample, you must have the appropriate JDBC data source configured so that it can be accessed by your application server. The report used in this example is not included with the tutorials.

ParameterFieldsViewReport.jsp

<%@ page import="com.crystaldecisions.report.web.viewer.*" %>

<%@ page import="com.crystaldecisions.sdk.occa.report.data.*"  %>

<%@ page import="com.crystaldecisions.reports.sdk.ReportClientDocument" %>

<%

    Object reportSource = session.getAttribute("reportSource");

    if (reportSource == null)

    {

       String report = "/reports/sample.rpt";

       ReportClientDocument reportClientDoc = new ReportClientDocument();

       reportClientDoc.open(report, 0);

       reportSource = reportClientDoc.getReportSource();

       session.setAttribute("reportSource", reportSource);

    }

    Fields fields = new Fields();

    ParameterField pfield1 = new ParameterField();

    Values vals1 = new Values();

    ParameterFieldDiscreteValue pfieldDV1 = new ParameterFieldDiscreteValue();

    pfield1.setName("Country");

    pfield1.setReportName("");

    pfieldDV1.setValue("Spain");

    pfieldDV1.setDescription("The country is Spain.");

    vals1.add(pfieldDV1);

    pfield1.setCurrentValues(vals1);

    fields.add(pfield1);

    CrystalReportViewer viewer = new CrystalReportViewer();

    viewer.setReportSource(reportSource);

    viewer.setParameterFields(fields);

    viewer.setEnableParameterPrompt(false);

    if (session.getAttribute("refreshed") == null)

    {

    viewer.refresh();

    session.setAttribute("refreshed", "true");

    }

    viewer.setOwnPage(true);

    viewer.processHttpRequest(request, response, getServletConfig().getServletContext(), null);

%>



Business Objects
http://www.businessobjects.com/
Support services
http://www.businessobjects.com/services/support/