Quantcast
Channel: SCN : Popular Discussions - SAP Crystal Reports, version for Eclipse
Viewing all articles
Browse latest Browse all 893

Crystal reports viewer (JSP - Eclipse) charts missing

$
0
0

I wonder if anyone out there could enlighten me re the following weirdness. I'm pretty new to JSP and even newer to Crystal Reports so it's likely a newbie mistake. 

 

I have a report (an .rpt file) which contains a chart (all good so far). In Eclipse, I can right click the chart file and use a wizard to generate a jsp file, either a version using jsp tags or using java code snippets. I want the latter, so that I can have a bit more control over the thing.

In the jsp tags version, charts show. In the code snippets version, charts don't show. Everything else is working fine, the correct data is shown etc.

My code looks like this:

 

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="ISO-8859-1"%><%@ page
import="com.businessobjects.samples.CRJavaHelper,
com
.crystaldecisions.report.web.viewer.CrystalReportViewer,
com
.crystaldecisions.sdk.occa.report.application.OpenReportOptions,
com
.crystaldecisions.sdk.occa.report.application.ReportClientDocument,
com
.crystaldecisions.sdk.occa.report.lib.ReportSDKExceptionBase,
java
.sql.Connection,
java
.sql.DriverManager,
java
.sql.ResultSet,
java
.sql.SQLException,
java
.sql.Statement, com.crystaldecisions.sdk.occa.report.definition.IReportDefinition,
com
.crystaldecisions.sdk.occa.report.definition.IReportObject,
com
.crystaldecisions.report.web.viewer.CrToolPanelViewTypeEnum
"%><%
// This sample code calls methods from the CRJavaHelper class, which
// contains examples of how to use the BusinessObjects APIs. You are free to
// modify and distribute the source code contained in the CRJavaHelper class.

try{

   
String reportName ="CrystalReport1.rpt";
    session
.removeAttribute(reportName);
   
//ReportClientDocument clientDoc = (ReportClientDocument) session.getAttribute(reportName);
   
ReportClientDocument clientDoc =null;
   
//clientDoc = null;
   
if(clientDoc ==null){
       
System.out.println ("ClientDoc is definitely null");
       
// Report can be opened from the relative location specified in the CRConfig.xml, or the report location
       
// tag can be removed to open the reports as Java resources or using an absolute path
       
// (absolute path not recommended for Web applications).

        clientDoc
=newReportClientDocument();
        clientDoc
.setReportAppServer(ReportClientDocument.inprocConnectionString);

       
// Open report
        clientDoc
.open(reportName,OpenReportOptions._openAsReadOnly);

       
IReportObject img = clientDoc.getReportDocument().getReportDefinition().findObjectByName("Picture2");


       
// ****** BEGIN SET RUNTIME DATABASE CREDENTIALS **************** 
       
{
           
System.out.println ("BEGIN SET RUNTIME DATABASE CREDENTIALS");
           
String connectString ="jdbc:mysql://localhost:3306/crystaltest";
           
String driverName ="com.mysql.jdbc.Driver";
           
StringJNDIName="";
           
String userName ="root";           // TODO: Fill in database user
           
String password ="";       // TODO: Fill in password

           
// Switch all tables on the main report and sub reports
           
CRJavaHelper.changeDataSource(clientDoc, userName, password, connectString, driverName,JNDIName);

           
// logon to database
           
CRJavaHelper.logonDataSource(clientDoc, userName, password);
       
}
       
// ****** END SET RUNTIME DATABASE CREDENTIALS ****************        


       
// ****** BEGIN POPULATE WITH RESULTSET SNIPPET **************** 
       
{
           
// **** POPULATE MAIN REPORT ****
           
{
               
System.out.println ("POPULATE MAIN REPORT 1");
                
// Connection Info for fetching the resultSet
               
String connectStr ="jdbc:mysql://localhost:3306/crystaltest";
               
String driverName ="com.mysql.jdbc.Driver";
               
String userName ="root";       // TODO: Fill in database user
               
String password ="";   // TODO: Fill in valid password

               
// TODO: Ensure this query is valid in your database. An exception will be thrown otherwise.
               
String query =" SELECT  `job`.`id`, `job`.`name`  FROM `job`";

               
// As long the Resultset schema has the same field names and types,
               
// then the Resultset can be used as the datasource for the table
               
String tableAlias ="job";      // TODO: Change to correct table alias

               
// Push the Java ResultSet into the report (this will then be the datasource of the report)
               
CRJavaHelper.passResultSet(clientDoc, fetchResultSet(driverName, connectStr, userName, password, query),
                    tableAlias
,"");
           
}

           
// **** POPULATE MAIN REPORT ****
           
{
               
System.out.println ("POPULATE MAIN REPORT 2");
                
// Connection Info for fetching the resultSet
               
String connectStr ="jdbc:mysql://localhost:3306/crystaltest";
               
String driverName ="com.mysql.jdbc.Driver";
               
String userName ="root";       // TODO: Fill in database user
               
String password ="";   // TODO: Fill in valid password

               
// TODO: Ensure this query is valid in your database. An exception will be thrown otherwise.
               
String query =" SELECT `person`.`lastName`, `person`.`job_id`, `person`.`firstName`, `person`.`dateOfBirth` FROM `person`";

               
// As long the Resultset schema has the same field names and types,
               
// then the Resultset can be used as the datasource for the table
               
String tableAlias ="person";       // TODO: Change to correct table alias

               
// Push the Java ResultSet into the report (this will then be the datasource of the report)
               
CRJavaHelper.passResultSet(clientDoc, fetchResultSet(driverName, connectStr, userName, password, query),
                    tableAlias
,"");
           
}


       
}
       
// ****** END POPULATE WITH RESULTSET SNIPPET ****************


       
// Store the report document in session
       
//session.setAttribute(reportName, clientDoc);

   
}


   
// ****** BEGIN CONNECT CRYSTALREPORTPAGEVIEWER SNIPPET **************** 
   
{
       
System.out.println ("BEGIN CONNECT CRYSTALREPORTPAGEVIEWER SNIPPET");
       
// Create the CrystalReportViewer object
       
CrystalReportViewer crystalReportPageViewer =newCrystalReportViewer();

       
String reportSourceSessionKey = reportName+"ReportSource";
       
//Object reportSource = session.getAttribute(reportSourceSessionKey);
       
Object reportSource =null;
       
if(reportSource ==null)
       
{
            reportSource
= clientDoc.getReportSource();
           
//session.setAttribute(reportSourceSessionKey, reportSource);
       
}
       
//  set the reportsource property of the viewer
        crystalReportPageViewer
.setReportSource(reportSource);

       
// Apply the viewer preference attributes

       
//crystalReportPageViewer.setHasLogo(true);
       
//crystalReportPageViewer.setHasToggleGroupTreeButton(false);
       
//crystalReportPageViewer.setEnableDrillDown(false);
       
//crystalReportPageViewer.setEnableParameterPrompt(false);
       
//crystalReportPageViewer.setHasDrilldownTabs(false);
       
//crystalReportPageViewer.setDisplayGroupTree(false);
       
//crystalReportPageViewer.setHasRefreshButton(false);
       
//crystalReportPageViewer.setHasSearchButton(false);
       
//crystalReportPageViewer.setDisplayToolbar(false);
       
//crystalReportPageViewer.setToolPanelViewType(CrToolPanelViewTypeEnum.none);
       
//crystalReportPageViewer.setHasToggleParameterPanelButton(false);
       
//crystalReportPageViewer.setDocumentViewType(arg0);
       
//crystalReportPageViewer.setHasExportButton(true);
       
//crystalReportPageViewer.setHasPageBottomToolbar(true);
       
//crystalReportPageViewer.setViewState(arg0);


       
// Process the report
        crystalReportPageViewer
.processHttpRequest(request, response, application,null);
   
}
   
// ****** END CONNECT CRYSTALREPORTPAGEVIEWER SNIPPET ****************     


}catch(ReportSDKExceptionBase e){
    out
.println(e);
}catch(SQLException e){
    out
.println(e);
}

%><%!
// Simple utility function for obtaining result sets that will be pushed into the report. 
// This is just standard querying of a Java result set and does NOT involve any
// Crystal Reports Java SDK functions.

privatestaticResultSet fetchResultSet(String driverName,
       
String connectStr,String userName,String password,String query)throwsSQLException,ClassNotFoundException{

   
//Load JDBC driver for the database that will be queried   
   
Class.forName(driverName);

   
Connection connection =DriverManager.getConnection(connectStr, userName, password);
   
Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);

   
//Execute query and return result sets
   
return statement.executeQuery(query);

}%>

 

 

If anyone could advise whether anything I'm doing here is completely insane and breaking this thing please let me know!

Cheers,

Me


Viewing all articles
Browse latest Browse all 893

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>