CRYSTAL REPORTS CON OBJETOS EN JAVA
Plain Old Java Objects (POJO)
When designing a class to use as a POJO, you can use a Java Project, a J2EE Utility Project, or a Crystal Reports Web Project.
Your POJO class must have a schema that is compatible with a table in your report. The names and types are case insensitive, but they must match.
To view POJO runtime data in your report, you'll update the report with a DatabaseController. You'll instantiate a class, put the data into an object collection, and then call Crystal Reports JavaDatabaseController.setDataSource API.
EXAMPLE
-------------
import java.sql.*;
public class ReportData
{
public String firstName;
private String lastName;
private int age;
private Date birthDay;
public ReportData(String firstName, String lastName, int age, Date birthDay)
{
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.birthDay = birthDay;
}
public String getLastName()
{
return lastName;
}
public int getAge() {return age;}
public Date getBirthDay() {return birthDay;}
}
-------------
To update the report
To create a DatabaseController, call getDatabaseController from the instance of ReportClientDocument that contains your report.
DatabaseController dbc = rcd.getDatabaseController();
To set the datasource for your DatabaseController, call setDataSource and pass the object collection, POJO class definition, and the table name, as parameters.
String reportTable = "pojoReport";
dbc.setDataSource(data, ReportData.class, reportTable, reportTable);
-------------
<%@ page import="com.crystaldecisions.report.web.viewer.CrystalReportViewer,
com.crystaldecisions.sdk.occa.report.reportsource.IReportSource,
com.crystaldecisions.reports.sdk.*,
java.sql.*"
language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"
%>
<%
String report = "pojoReport.rpt";
ReportClientDocument rcd = new ReportClientDocument();
rcd.open(report, 0);
DatabaseController dbc = rcd.getDatabaseController();
//Create the POJO data
ReportData data1 = new ReportData("B.B.", "King", 6, new Date(25, 9, 16));
ReportData data2 = new ReportData("Muddy", "Waters", 7, new Date(15, 4, 4));
ReportData data3 = new ReportData("John Lee", "Hooker", 8, new Date(16, 8, 16));
ReportData data4 = new ReportData("Otis", "Rush", 9, new Date(34, 4, 29));
ReportData data5 = new ReportData("Buddy", "Guy", 10, new Date(36, 7, 30));
String reportTable = "pojoReport"; //The table name in your report.
java.util.ArrayList objects = new java.util.ArrayList();
objects.add(data1);
objects.add(data2);
objects.add(data3);
objects.add(data4);
objects.add(data5);
dbc.setDataSource(objects, ReportData.class, reportTable, reportTable);
IReportSource reportSource = rcd.getReportSource();
CrystalReportViewer viewer = new CrystalReportViewer();
viewer.setOwnPage(true);
viewer.setReportSource(reportSource);
viewer.processHttpRequest(request, response, getServletConfig().getServletContext(), null);
%>