This section contains a series of short exercises designed to illustrate some of the basic features of the Report API. For more details about any of the features described in this section, please see the Programming Guide portion of the documentation.
The code, given in this guide, has been created with the following in mind:
Any code given in this guide is also under the <EspressReport installation directory>/help/quickstart/src directory and any java application's class file will be under the <EspressReport installation directory>/help/quickstart/classes directory. Any HTML files will be under the <EspressReport installation directory>/help/quickstart/html directory. Similarly, any templates would be under the help/quickstart/templates directory.
The naming convention for the files will be as follows:
The name, QuickStart, followed by the Chapter number, followed by the Section number, followed by the file extension. For instance, QuickStart421.java refers to the exercise in Chapter 4 (which is the current chapter you are perusing), Section 2.1 . QuickStart422.html refers to the html file used in the exercise in Chapter 4, Section 2.2.
Most of the files need not be moved in order to run the exercises. In the few instances where the files have to be moved and/or modified, instructions will be given.
In order to successfully use the Quick Start API Guide:
The templates (referenced in this guide), which uses a database as a data source, uses the HSQL java database. For windows users, there are alternate templates available, which use Access. These templates can be found under the <EspressReport installation directory>/help/quickstart/templates/Access directory. The templates will again follow the naming convention specified above along with "_Acc" (without the double quotes) before the ".rpt" (without the double quotes) extension.
Depending on the version of the Tomcat server you are using, the servlet context /servlet/ may be commented out. Please check the <Tomcat installation directory>/conf/web.xml and uncomment the following lines:
and
The block of statements is commented if there is a <!-- at the beginning and a --> at the end. So if the above blocks are commented out, please uncomment and restart your Tomcat server.
The "classes" (without the double quotes) must also exist in your <Tomcat installation directory>/webapps/ROOT/WEB-INF directory. If the directory does not exist, please create the directory and restart your Tomcat server.
While running the code, you may see the message "Failed to read espressmanager.cfg. Use default host and port no. 22071." (without the double quotes). This is not an error message. This message simply states that espressmanager.cfg was not found and that it would look for and connect to EspressManager running on the same machine, as the code, and using port number 22071.
Please note that while EspressReport API can be used without EspressManager and in other application servers, the code in this guide was designed with EspressManager and Tomcat in mind. Please refer to the Programming Guide (Deploying w/o EspressManager and Servlets & Java Server Pages) to switch to other configurations.
The code has also been implemented with the idea that everything (i.e., EspressManager, Tomcat server and the client) is on the same machine. The code is single-threaded and set to use the same machine for the client and server for demonstration purposes. You can generate multi-threaded code using EspressReport API, in a multi-client server environment. To use in a multi-machine environment, you will have to edit the code (and/or accompanying HTML files). Please refer to the Programming Guide (Deploying with EspressManager) for further details.
The following sections show how to run a pre-existing template (QuickStart42.rpt located in the <EspressReport installation directory>/help/quickstart/templates directory) in an application, applet and servlet.
Each section shows the code to generate the report and any steps necessary to deploy.
The following code shows how to display an existing report template (in this case QuickStart42.rpt) in an application:
public class QuickStart421 extends Applet {
public static void main(java.lang.String[] args) {
public void init() {
Component doQuickStart421(Object object) {
The class file for the above source is located in the <EspressReport installation directory>/help/quickstart/classes directory.
When the class file is run, using the command "java QuickStart421" (without the double quotes), the following report is shown:
Report generated
The main part of the code is in the doQuickStart421 component. There, a QbReport object called report is created using the QuickStart42.rpt template. The following constructor is used:
The following html (QuickStart422.html in the <EspressReport installation directory>/help/quickstart/html directory) shows how to display an existing report template (in this case QuickStart42.rpt) in an applet:
The same code used for the application (given in the previous section) can be used to show the report in an applet as well. To deploy the applet, copy
When the html file, using the URL "http://localhost:8080/QuickStart422.html" (without the double quotes), is run, the following report is shown:
Report generated
Please note that the images will not be shown because of a security restriction in the default configuration of the browser.
The main part of the code is in the doQuickStart421 component. There, a QbReport object called report is created using the QuickStart42.rpt template. The following constructor is used:
The following code shows how to display an existing report template (in this case QuickStart42.rpt) in an servlet:
public class QuickStart423 extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
public String getServletInfo() {
To deploy the servlet:
When the servlet, using the URL "http://localhost:8080/servlet/QuickStart423" (without the double quotes), is run, the following report is shown:
Report generated
The main part of the code is in the QuickStart423. There, a QbReport object called report is created using the QuickStart42.rpt template. The following constructor is used:
The QbReport object, report, was then exported as a DHTML document to the servlet's response stream using the export method:
Besides deploying the report using sevlets, it is also possible to deploy it using JSP. An example of deploying reports using JSP/Java Bean technology can be found in the "<EspressReport installation directory>/help/examples/jsp/deploy" folder. The same folder contains a README.txt file that explains how to setup this example on your servlet container.
The following piece of code shows how to display the report in an application/applet using Page Viewer instead of Report Viewer.
public class QuickStart424 extends Applet {
public static void main(java.lang.String[] args) {
public void init() {
Component doQuickStart424(Object parent) {
// Location of the report
String report = "help/quickstart/templates/QuickStart42.rpt";
// Show the Report
if (parent instanceof Applet)
The class file for the above source is located in the <EspressReport installation directory>/help/quickstart/classes directory. When the class file is run, using the command "java QuickStart424" (without the double quotes), the following report is shown:
Generated Report
Notice that a QbReport object is not created. Instead the .rpt file name is passed directly into the component:
In the back-end, the .rpt will be exported to VIEW and PAGE files that will be loaded into the viewer. When running without EspressManager, the report will first have to be exported in VIEW format. The resulting VIEW file can then be passed into the Page Viewer component.
The Page Viewer code can also run as an applet. The following html (QuickStart424.html in the <EspressReport installation directory>/help/quickstart/html directory) shows how to display an existing report template (in this case QuickStart42.rpt) in an Page Viewer applet:
The same code used for the application (given in the previous section) can be used to show the report in an applet as well. To deploy the applet, copy
4.3.) Create a Report Programmatically
The following sections show how to create a report programmatically and apply a template, QuickStart43.rpt (located in the <EspressReport installation directory>/help/quickstart/templates directory) to the report in an application.
Each section shows the code to generate the report and any steps necessary to deploy.
4.3.1.) Map Summary Break ColInfo
The following code shows how to create a Summary Break report programmatically (using QuickStart43.txt as the data source):
public class QuickStart431 extends Applet {
// main method for application
public static void main(java.lang.String[] args) {
// init method for applet
public void init() {
// creates report and return it
Component doQuickStart431(Object object) {
The class file for the above source is located in the <EspressReport installation directory>/help/quickstart/classes directory.
When the class file is run, using the command "java QuickStart431" (without the double quotes), the following report is shown:
Report generated
Please note that when the above code is run, the report generated is of default look and feel without any additional formatting.
The main part of the code is in the doQuickStart431 component. There, a QbReport object called report is created using the specified Column Mapping, the specified Report Type and the specified Data Source. The following constructor is used:
You can pass in a different formatting (i.e., different from the default look and feel) by specifying a template during the creation of the QbReport object.
The following code shows how to create a Summary Break report programmatically (using QuickStart43.txt as the data source and QuickStart43.rpt as the template):
public class QuickStart432 extends Applet {
// main method for application
public static void main(java.lang.String[] args) {
// init method for applet
public void init() {
// creates report and return it
Component doQuickStart432(Object object) {
The class file for the above source is located in the <EspressReport installation directory>/help/quickstart/classes directory.
When the class file is run, using the command "java QuickStart432" (without the double quotes), the following report is shown:
Report generated
The main part of the code is in the doQuickStart432 component. There, a QbReport object called report is created using the specified Column Mapping, the specified Report Type, the specified Data Source and the specified Report Template. The following constructor is used:
4.4.) Modify Data Source of a Report
The following code shows how to modify a report's (and its accompanying sub-report's, drill down's and independent chart's) data source, without having to create a new QbReport object. The QbReport object (created from QuickStart44.rpt) is opened with backup data (this is so that the database is not hit unnecessarily). The datasource is then changed to the Access Woodview database.
public class QuickStart44 extends Applet {
public static void main(java.lang.String[] args) {
try {
QuickStart44 doReport = new QuickStart44();
Frame frame = new Frame();
frame.setLayout(new BorderLayout());
frame.add("Center", doReport.doQuickStart44(frame));
frame.setSize(600, 600);
frame.setVisible(true);
public void init() {
setLayout(new BorderLayout());
add("Center", doQuickStart44(this));
Component doQuickStart44(Object object) {
// Create the report using the two rows of back-up data
QbReport report = new QbReport(object, "help/quickstart/templates/QuickStart44.rpt",
false, false, false, true);
// Begin Code : Specification for new Database
String newDatabaseURL = "jdbc:odbc:Woodview";
String newDatabaseDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String newDatabaseUserid = "";
String newDatabasePassword = "";
//End Code : Specification for new Database
try {
// Begin Code : Change the data source of the main report and all ancillary templates
report.getInputData().setAllDatabaseInfo(newDatabaseURL, newDatabaseDriver, newDatabaseUserid, newDatabasePassword);
// End Code : Change the data source of the main report and all ancillary templates
ex.printStackTrace();
return (new Viewer().getComponent(report));
The class file for the above source is located in the <EspressReport installation directory>/help/quickstart/classes directory.
When the class file is run, using the command "java QuickStart44" (without the double quotes), the following report is shown:
Report generated
The main part of the code is in the doQuickStart44 component. There, a QbReport object called report is created. The data source for the report, subreport, drill down and chart (with independent data source) is changed using the following method in the quadbase.reportdesigner.util.IInputData interface:
4.4.1.) Modify Data Source and Query of a Report (with Sub-Report)
The following code shows how to modify a report's (and its accompanying sub-report's) data source, without having to create a new QbReport object. The QbReport object (created from QuickStart441_Acc.rpt) is opened with backup data (this is so that the database is not hit unnecessarily). The datasource is then changed from the Access Woodview database to the HSQLDB Woodview database.
public class QuickStart441 extends Applet {
public static void main(java.lang.String[] args) {
try {
QuickStart441 doReport = new QuickStart441();
Frame frame = new Frame();
frame.setLayout(new BorderLayout());
frame.add("Center", doReport.doQuickStart441(frame));
frame.setSize(600, 600);
frame.setVisible(true);
public void init() {
setLayout(new BorderLayout());
add("Center", doQuickStart441(this));
Component doQuickStart441(Object object) {
// Create the report using the two rows of back-up data
QbReport report = new QbReport(object, "help/quickstart/templates/Access/QuickStart441_Acc.rpt",
false, false, false, true);
// Begin Code : Specification for new Database
String newDatabaseURL = "jdbc:hsqldb:help/examples/DataSources/database/woodview";
String newDatabaseDriver = "org.hsqldb.jdbcDriver";
String newDatabaseUserid = "sa";
String newDatabasePassword = "";
String newDatabaseReportQuery = "select year(o.orderdate) as \"Year\", month(o.orderdate) as \"Month\", count(o.orderid) as \"Orders\", sum(od.quantity) as \"Units Sold\", sum((p.unitprice + od.staincost) * od.quantity) as \"Total Sales\" from orders o, order_details od, products p where o.orderid = od.orderid and p.productid = od.productid group by year(o.orderdate), month(o.orderdate) order by year(o.orderdate), month(o.orderdate);";
String newDatabaseSubReportQuery = "select c.region as \"Region\", year(o.orderdate) as \"Year\", sum((p.unitprice + od.staincost) * od.quantity) as \"Total Sales\" from customers c, orders o, products p, order_details od where c.customerid = o.customerid and o.orderid = od.orderid and od.productid = p.productid group by c.region, year(o.orderdate);";
// Get the query and pass in new database info
DBInfo newSubReportDatabaseInfo = new DBInfo(newDatabaseURL, newDatabaseDriver, newDatabaseUserid, newDatabasePassword, newDatabaseSubReportQuery);
subReport.getInputData().setDatabaseInfo(newSubReportDatabaseInfo);
// End Code : Get a handle to the Sub-Report and change its data source
// Begin Code : Change the data source of the main report
// Get the query and pass in new database info
DBInfo newReportDatabaseInfo = new DBInfo(newDatabaseURL, newDatabaseDriver, newDatabaseUserid, newDatabasePassword, newDatabaseReportQuery);
report.getInputData().setDatabaseInfo(newReportDatabaseInfo);
// End Code : Change the data source of the main report
ex.printStackTrace();
return (new Viewer().getComponent(report));
The class file for the above source is located in the <EspressReport installation directory>/help/quickstart/classes directory.
When the class file is run, using the command "java QuickStart441" (without the double quotes), the following report is shown:
Report generated
The main part of the code is in the doQuickStart441 component. There, a QbReport object called report is created. The data source for the report and the sub-report is changed using the following method in the quadbase.reportdesigner.util.IInputData interface:
The sub-report is obtained by getting a handle to the cell containing the sub-report and then calling the sub-report. The sub-report is also opened using its backup data. This is done by:
(QbReport)subreport = (QbReport)subReportObject.getSubReport(boolean isEnterpriseServer, boolean optimizeMemory, boolean useBackupData, IReport report);
Please note that if you wish to change the data source from the HSQLDB Woodview database to the Access Woodview database , you will need to change the following lines of code from:
// Begin Code : Specification for new Database
String newDatabaseURL = "jdbc:hsqldb:help/examples/DataSources/database/woodview";
String newDatabaseDriver = "org.hsqldb.jdbcDriver";
String newDatabaseUserid = "sa";
String newDatabasePassword = "";
String newDatabaseReportQuery = "select year(o.orderdate) as \"Year\", month(o.orderdate) as \"Month\", count(o.orderid) as \"Orders\", sum(od.quantity) as \"Units Sold\", sum((p.unitprice + od.staincost) * od.quantity) as \"Total Sales\" from orders o, order_details od, products p where o.orderid = od.orderid and p.productid = od.productid group by year(o.orderdate), month(o.orderdate) order by year(o.orderdate), month(o.orderdate);";
String newDatabaseSubReportQuery = "select c.region as \"Region\", year(o.orderdate) as \"Year\", sum((p.unitprice + od.staincost) * od.quantity) as \"Total Sales\" from customers c, orders o, products p, order_details od where c.customerid = o.customerid and o.orderid = od.orderid and od.productid = p.productid group by c.region, year(o.orderdate);";
to
// Begin Code : Specification for new Database
String newDatabaseURL = "jdbc:odbc:Woodview";
String newDatabaseDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String newDatabaseUserid = "";
String newDatabasePassword = "";
String newDatabaseReportQuery = "select year(o.orderdate) as \"Year\", month(o.orderdate) as \"Month\", count(o.orderid) as \"Orders\", sum(od.quantity) as \"Units Sold\", sum((p.unitprice + od.staincost) * od.quantity) as \"Total Sales\" from orders o, [order details] od, products p where o.orderid = od.orderid and p.productid = od.productid group by year(o.orderdate), month(o.orderdate) order by year(o.orderdate), month(o.orderdate);";
String newDatabaseSubReportQuery = "select c.region as \"Region\", year(o.orderdate) as \"Year\", sum((p.unitprice + od.staincost) * od.quantity) as \"Total Sales\" from customers c, orders o, products p, [order details] od where c.customerid = o.customerid and o.orderid = od.orderid and od.productid = p.productid group by c.region, year(o.orderdate);";
4.4.2.) Modify Data Source and Query of a Parameterized Report (with Parameterized SubReport)
The following code shows how to modify a report's and its accompanying sub-report's parameterized data sources, without having to create a new QbReport object. The QbReport object (created from QuickStart442_Acc.rpt) is opened with backup data (this is so that the database is not hit unnecessarily). The datasource is then changed from the Access Woodview database to the HSQLDB Woodview database..
}
}
The class file for the above source is located in the <EspressReport installation directory>/help/quickstart/classes directory.
When the class file is run, using the command "java QuickStart442" (without the double quotes), the following report is shown:
Report generated
The main part of the code is in the doQuickStart442 component. There, a QbReport object called report is created. The data source for the report and the sub-report is changed using the following method in the quadbase.reportdesigner.util.IInputData interface:
However, because both reports use a parameterized report, a separate class file (QueryFileInfo) was created which used the interface quadbase.reportdesigner.util.IQueryFileInfo to pass in the database connection information and the parameter properties information as well. An object of the class QueryFileInfo (with the required information) is then passed as the argument for the setDatabaseInfo() method.
The parameter information is obtained by getting the database connection information (by called the getDatabaseInfo() method), casting it to IQueryFileInfo and using the following method in IQueryFileInfo:
The above method call returns the complete parameter properties information for all the parameters defined in the report.
The code also passes in the values for the parameters directly into the report, rather than have the user be prompted to specify the values. The values are entered by going to each parameter and specifying them before passing them to the report object. The following method, in IQueryInParam, is used to specify the value:
The sub-report is obtained by getting a handle to the cell containing the sub-report and then calling the sub-report. The sub-report is also opened using its backup data. This is done by:
(QbReport)subreport = (QbReport)subReportObject.getSubReport(boolean isEnterpriseServer, boolean optimizeMemory, boolean useBackupData, IReport report);
Please note that if you wish to change the data source from the HSQLDB Woodview database to the Access Woodview database , you will need to change the following lines of code from:
// Begin Code : Specification for new Database
String newDatabaseURL = "jdbc:hsqldb:help/examples/DataSources/database/woodview";
String newDatabaseDriver = "org.hsqldb.jdbcDriver";
String newDatabaseUserid = "sa";
String newDatabasePassword = "";
String newDatabaseSubReportQuery = "select c.categoryname as \"Category\", p.productname as \"Product\", cu.region as \"Region\", sum((od.staincost + p.unitprice) * od.quantity) as \"Sales\" from categories c, products p, customers cu, orders o, order_details od where c.categoryid = p.categoryid and p.productid = od.productid and cu.customerid = o.customerid and o.orderid = od.orderid and c.categoryname IN (:category) group by c.categoryname, p.productname, cu.region;";
to
// Begin Code : Specification for new Database
String newDatabaseURL = "jdbc:odbc:Woodview";
String newDatabaseDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String newDatabaseUserid = "";
String newDatabasePassword = "";
String newDatabaseSubReportQuery = "select c.categoryname as \"Category\", p.productname as \"Product\", cu.region as \"Region\", sum((od.staincost + p.unitprice) * od.quantity) as \"Sales\" from categories c, products p, customers cu, orders o, [order details] od where c.categoryid = p.categoryid and p.productid = od.productid and cu.customerid = o.customerid and o.orderid = od.orderid and c.categoryname IN (:category) group by c.categoryname, p.productname, cu.region;";
You can also pass in a java.sql.Connection object, instead of passing in the URL, driver, userid and password of the database. For example, if you wish to pass in a Connection object, conn, you would need to change the following lines of code:
to
The following code shows how to modify certain elements of the report programmatically. The QbReport object is created from QuickStart45.rpt . When the code is run, the original report is first shown and when the "Change" (without the double quotes) button (located at the bottom) is clicked, some of the report elements will change.
// Set up Frame
public class QuickStart45 extends Frame {
// Start Frame
public QuickStart45() {
// Create Empty Report and set up initial data and wipe out empty
report data
public void start() {
// What to do with the button
public boolean action(Event e, Object o) {
// Begin Code :Add a formula
ReportCell formulaCell = new ReportCell();
Formula formula = new Formula("totalSales", "sum({Total Sales})");
report.addFormula(formula);
formulaCell.setFormulaObj(formula);
formulaCell.setBgColor(new Color(255,255,255));
formulaCell.setFontColor(new Color(0,0,0));
formulaCell.setFont(new Font("Dialog", Font.BOLD, 8));
formulaCell.setAlign(IAlignConstants.ALIGN_LEFT);
formulaCell.setWidth(1.0);
formulaCell.setHeight(0.25);
formulaCell.setX(4.1);
formulaCell.setY(0);
report.getReportFooter().addData(formulaCell);
// End Code :Add a formula
// Begin Code : Add a label
ReportCell label = new ReportCell();
label.setText("Total sales for top 10 customers:");
label.setBgColor(new Color(255,255,255));
label.setFontColor(new Color(0,54,100));
label.setFont(new Font("Dialog", Font.BOLD, 8));
label.setAlign(IAlignConstants.ALIGN_RIGHT);
label.setWidth(2.1);
label.setHeight(0.4);
label.setX(1.9);
label.setY(0);
report.getReportFooter().addData(label);
// End Code : Add a label
remove(reportComponent);
viewer = new Viewer();
reportComponent = viewer.getComponent(report);
add("Center", reportComponent);
pack();
return true;
public Dimension getPreferredSize() {
//Start
public static void main(String[] args) {
The class file for the above source is located in the <EspressReport installation directory>/help/quickstart/classes directory.
When the class file is run, using the command "java QuickStart45" (without the double quotes), the following report is shown:
Report generated
When the "Change" (without double quotes") button is clicked, the following report is then shown:
Report generated after Change button is clicked
The main part of the code is in the action class. Report properties such as Dual Color are turned on and a formula, a label and a title are added to the QbReport object.
Dual colors are set using the following code. The dual color property is set for each table column and the alternate background color, font color and font are specified.
Adding a title to the Report Header is done using the following code. The ReportCell object is first created, the title text then set and the ReportCell properties such as height, width, x-position and y-position are specified before adding it to the Report Header section.
A formula and a label are specified likewise. A ReportCell object is first created, the formula or label set and the ReportCell properties specified before adding the newly created formula or label ReportCell object to the appropriate section.
ReportCell label = new ReportCell();
label.setText(String text);
label.setBgColor(Color backgroundColor);
label.setFontColor(Color fontColor);
label.setFont(Font font);
label.setAlign(int alignment);
label.setWidth(double width);
label.setHeight(double height);
label.setX(double xPosition);
label.setY(double yPosition);
<Handle to desired Report Section>.addData(label);
The following sections show how to run a pre-existing template (QuickStart46.rpt located in the <EspressReport installation directory>/help/quickstart/templates directory) which uses a parameterized query as the data source.
Each section shows the code to generate the report and any steps necessary to deploy.
4.6.1.) Pass in Parameter values
The following code shows how to display an existing report template (in this case QuickStart46.rpt), which uses a parameterized query, in an application. The parameter values are passed when creating the report.
public class QuickStart461 extends Applet {
public QuickStart461(){};
public static void main(java.lang.String[] args) {
Component createReport(Object parent) {
// Show the Report
Viewer viewer = new Viewer();
Component comp = viewer.getComponent(report);
return comp;
}
}
The class file for the above source is located in the <EspressReport installation directory>/help/quickstart/classes directory.
When the class file is run, using the command "java QuickStart461" (without the double quotes), the following report is shown:
Report generated
The main part of the code is in the createReport component. There, a QbReport object called report is created using the QuickStart46.rpt template. The parameter values are passed using the following constructor:
Both query parameter and formula parameter values are declared in the same order as the parameters were defined. Query parameters which take in multiple values are declared as a Vector object which then contains the different multiple values.
Please note that if you are using the Access templates, you will need to change the following lines of code from:
to
4.6.2.) Pass in Parameter values using getAllParameters
In addition to the above, you can also pass in parameter values using the getAllParameters method in QbReport. The following code shows how to display an existing report template (in this case QuickStart46.rpt), which uses a parameterized query, in an application. The report is opened with backup data (to avoid the initial hit to the database) and the parameter values are set. The report is then refreshed with the data.
public class QuickStart462 extends Applet {
public QuickStart462(){};
public static void main(java.lang.String[] args) {
Component createReport(Object parent) {
try {
report.getAllParameters().get(0).setValues((Vector)queryParams[0]);
report.getAllParameters().get(1).setValue(queryParams[1]);
report.getAllParameters().get(2).setValue(queryParams[2]);
report.getAllParameters().get(3).setValue(formulaParams[0]);
report.refreshWithOriginalData();
} catch (Exception ex)
{
// Show the Report
Viewer viewer = new Viewer();
Component comp = viewer.getComponent(report);
return comp;
The class file for the above source is located in the <EspressReport installation directory>/help/quickstart/classes directory.
When the class file is run, using the command "java QuickStart462" (without the double quotes), the following report is shown:
Report generated
The main part of the code is in the createReport component. There, a QbReport object called report is created using the QuickStart46.rpt template. The parameter values are passed using the following interface in QbReport:
Both query parameter and formula parameter values are declared in the same order as the parameters were defined. Query parameters which take in multiple values are declared as a Vector object which then contains the different multiple values.
Please note that if you are using the Access templates, you will need to change the following lines of code from:
to
4.6.3.) Use getParameterPage() and ParamReportGeneratorServlet
The following code shows how to display an existing report template (in this case QuickStart46.rpt), which uses a parameterized query, in a servlet. The servlet creates the QbReport object by opening the template using back-up data. A HTML page is then streamed asking for the parameter values. These values are passed to another servlet (the ParamReportGeneratorServlet servlet) and the QbReport object is created, from the given template, with the specified parameter values.
public class QuickStart463 extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
System.out.println("QuickStart463 Servlet: Do Get....");
System.out.println("QuickStart463 Servlet: Generate paramter html page...");
res.setContentType("text/html");
OutputStream toClient = res.getOutputStream();
try {
// Specify the parameters for connecting to ParamReportGeneratorServlet
report.setDynamicExport(true, "127.0.0.1", 8080);
// Specify report template location and export format desired
ParameterPage paramPage = report.getParameterPage(reportLocation, null, QbReport.DHTML, null);
Writer writer = new PrintWriter(toClient);
HtmlParameterPageWriter paramPageWriter = new HtmlParameterPageWriter(paramPage, writer);
paramPageWriter.writePage();
writer.flush();
writer.close();
}
public String getServletInfo() {
To deploy the servlet:
When the servlet, using the URL "http://localhost:8080/servlet/QuickStart463" (without the double quotes), is run, the following HTML page is shown:
HTML prompt page generated
Depending on what parameter values you pass in, a report similar to the following will be shown:
Report generated after passing in parameter values
The main part of the code is in the QuickStart463. There, a QbReport object called report is created using the QuickStart46.rpt template. The dynamic export is then called to use the ParamReportGeneratorServlet (provided with EspressReport) using the following lines:
The HTML file asking for the parameter values is then generated and passed to the OutputStream.
For more information about the parameter page writer classes go to section 3.5.7.11.3. of the Programming Guide. For an example of generating parameter page using CssHtmlParameterPageWriter which utilize CSS, go to <EspressReport>/help/examples/servlet/CssParamReport and follow the javadoc instructions.
4.7.) Deploy/Export Drill Down
The following code shows how to display an existing report template (in this case QuickStart47.rpt), which is a drill down report, in a servlet. The servlet creates the QbReport object by opening the template. A DHTML page, showing the contents of the first level, is then streamed. The next level report is obtained by clicking on the links. These links point to the DrillDownReportServlet. The values of the link (clicked on) are passed to the DrillDownReportServlet and the next level report (based on those values) is then generated and then streamed to the client.
public class QuickStart47 extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
System.out.println("QuickStart47 Servlet: Do Get....");
res.setContentType("text/html");
OutputStream toClient = res.getOutputStream();
try {
toClient.flush();
toClient.close();
}
public String getServletInfo() {
To deploy the servlet:
When the servlet, using the URL "http://localhost:8080/servlet/QuickStart47" (without the double quotes), is run, the following HTML page is shown:
Report generated
Depending on what link you click, a report similar to the following will be shown:
Report generated after clicking on a link
Again, depending on what link you click, a report similar to the following will be shown:
Report generated after clicking on a link
The main part of the code is in the QuickStart47. There, a QbReport object called report is created using the QuickStart47.rpt template. The dynamic export is then called to use the DrillDownReportServlet (provided with EspressReport) using the following lines:
The DHTML file for the top level report is then generated and passed to the OutputStream.
The following sections show how to run a pre-existing template (QuickStart48.rpt located in the <EspressReport installation directory>/help/quickstart/templates directory) in a servlet and have the generated report saved to a file or streamed to the client browser.
Each section shows the code to generate the report and any steps necessary to deploy.
The following code shows how to display an existing report template (in this case QuickStart48.rpt) in an servlet. The servlet then exports the report to a PDF file.
public class QuickStart481 extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
public String getServletInfo() {
To deploy the servlet:
When the servlet, using the URL "http://localhost:8080/servlet/QuickStart481" (without the double quotes), is run, the report is generated to your <EspressReport installation directory>/generatedReport.pdf and the following message is shown:
Message shown after report is generated
The main part of the code is in the QuickStart481. There, a QbReport object called report is created using the QuickStart48.rpt template. The following constructor is used. The QbReport object, report, was then exported as a PDF using the export method:
The following code shows how to display an existing report template (in this case QuickStart48.rpt) in an servlet. The servlet then streams the report (along with the chart) as a DTHML document to the client.
public class QuickStart482 extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
// Specify the parameters for connecting to RPTImageGenerator
report.setDynamicExport(true, "127.0.0.1", 8080);
// Stream report to client
report.export(QbReport.DHTML, toClient);
}
public String getServletInfo() {
To deploy the servlet:
When the servlet, using the URL "http://localhost:8080/servlet/QuickStart482" (without the double quotes), is run, the following HTML page is shown:
Report generated
The main part of the code is in the QuickStart482. There, a QbReport object called report is created using the QuickStart48.rpt template. The dynamic export is then called to use the RPTImageGenerator (provided with EspressReport) using the following lines:
The DHTML file for the top level report is then generated and passed to the OutputStream.
The following code shows how to launch the Report Designer (in default mode) via the Report API:
public class QuickStart49 {
public static void main(java.lang.String[] args) {
try {
public QuickStart49() {
// Begin Code : Start Designer in default mode and show the Designer
QbReportDesigner.setUseSysResourceImages(true);
QbReportDesigner designer = new QbReportDesigner(null);
designer.setVisible(true);
// End Code : Start Designer in default mode and show the Designer
The class file for the above source is located in the <EspressReport installation directory>/help/quickstart/classes directory.
To run the class file, move QuickStart49.class to the <EspressReport Installation directory> and use the command "java QuickStart49" (without the double quotes),.
The main part of the code is in the QuickStart49. There, a QbReportDesigner object called designer is created and shown: