Skip to Content
author's profile photo Former Member
Former Member

How many viewers in an application

Hi all,

I am using crystal reports for eclipse to create a reporting module.

I have following questions in this regard.

1) How many CrystalReportViewer objects to be used in the application. i-e either

A single viewer page for each report or (one jsp for every report that contains jsp code to get report parameters, and passing it report viewer object and also report document object etc.

2) if the viewer is on a separate jsp page then how to pass report parameters to it that are obtained in another jsp page and all set by using parameter, fields object.

Thanks in anticipitation!

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Posted on Jul 23, 2008 at 02:06 PM

    Hello Faisal,

    Fundamentally, DHTML Crystal Report Viewer works by postback. Any action on the viewer page posts back to the page - either JSP or Servlet - that instantiates the CrystalReportViewer class instance.

    The viewer itself is stateless - with each invocation or postback, you can create a new instance of the CrystalReportViewer to handle the request.

    The report is persisted via the report source object - that's the object you'd be storing in HTTP Session state.

    Your web application would have to be designed to accomodate the viewer postback request.

    There's several ways to accomodate this, and I'll list two (1) put the CrystalReportViewer in a separate page, or (2) detect whether a request is a postback from the CrystalReportViewer or not.

    Put the CrystalReportViewer in a separate page

    This is simplest. On a different page, you'd retrieve the Crystal Report, specify any params or logins, store the report source in an HTTP Session attribute, then send a client-side redirect to a different page with the CrystalReportViewer.

    On the viewer page, you'd instantiate the CrystalReportViewer, retrieve necessary objects from HTTP Session, set them to the viewer properties, and let the viewer process the HTTP request.

    In this scheme, if you're passing parameters, you'd create the Fields collection in the initial page, then save it to HTTP Session attribute. In the viewer page, you'd retrieve the attribute, and if not null, set it to the viewer property.

    Detect postback from the viewer

    Rather than having a separate page for the viewer, you'd have it in the same page where you'd retrieve the report. You can detect whether a request is a postback from the viewer or not by checking for the HTTP Request parameter named "CrystalEventTarget". If the request is a postback, then that parameter will be set to the name you've specified for the CrystalReportViewer.

    Here's a sketch:

    String viewerTarget = request.getParameter("CrystalEventTarget");
    if(viewerTarget != null && viewerTarget.equals("MyReportViewer")){
        // PostBack from the viewer, so merely retrieve the report source.
        reportSource = session.getAttribute("reportSource");
    } else {
        // Not viewer postback, so retrieve report, set logons here....
       ...
       reportSource = reportClientDocument.getReportSource();
       session.setAttribute("reportSource", reportSource);
    }
    
    CrystalReportViewer viewer = new CrystalReportViewer();
    // if need be, set other viewer properties here.
    viewer.setReportSource(reportSource);
    viewer.setName("MyReportViewer");
    viewer.processHttpRequest(request, response, getServletConfig().getServletContext(), null);
    

    Sincerely,

    Ted Ueda

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 23, 2008 at 02:10 PM

    I think the questions you have asked can be answered from within the documentation.

    First, you will only need one viewer jsp for your application; this viewer will render reports based on requests from your users.

    If the viewer is on a separate page, which is common practice, the way you ensure your parameters and database information is passed to the viewer is by putting the report source into a session object and then passing that to the viewer object.

    Please review the [Developer Library|https://boc.sdn.sap.com/developer/library] for more detailed information. In addition you can download the [JRC samples|https://smpdl.sap-ag.de/~sapidp/012002523100006008982008E/crxi_r2_jrc_web_smpl.zip] and have a look for the functionality you want to perform in your application.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.