Jump to content
Changes to the Jaspersoft community edition download ×

dynamic report generation including the jrxml file


prash194

Recommended Posts

Hello all,

 

I am new to Jasper Report and right now i am working on it for my project. Whatever i have done so far is first i create jrxml file compile it and use it to generate the report in different formats.

 

Actually i have to know in advance the number and types of data that the report should show.

But this is not my requirement as i have to make the reporting module that doesnot know in advance the datasource and its contents including the number of fields it holds.

 

So is there any way that i can use jasper to create report dynamically so that i dont have to make template file in advance.

Link to comment
Share on other sites

  • Replies 10
  • Created
  • Last Reply

Top Posters In This Topic

I have the same question. I need to generate report where in the number of fields and their types are not known in advance. Can it be done using jasper reports.

Is there any utility classes we can use to get this task done ?

 

Hey ... prash194 ... if you find the solution please let me know.

 

I thought of writing a utility class to generate jrxml file dynamically with some predefined format. That can be done but I don't think it is the ideal way.

 

cheers

Link to comment
Share on other sites

I guess you should generate your jrxml file on the fly, rather then using static jrxml.

Here is my point on how to accomplish your task:

 

1. Explore your datasource on the fly (get the column count, column data types).

2. Having all the data you need from [1] - generate .jrxml file. Use any XML building API. For example you may use JDOM.

3. Pass generated XML as an InputStream to JasperCompileManager.compileReport(...);

4. Fill report, show it to user or do anything you want.

Link to comment
Share on other sites

it can be simplier if u use jasper api to buil report design.. this code i found somewhere on thi sorum

Code:

/*
* ============================================================================
* The JasperReports License, Version 1.0
* ============================================================================
* * Copyright (C) 2001-2004 Teodor Danciu (teodord@users.sourceforge.net). All rights reserved.
* * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by Teodor Danciu (http://jasperreports.sourceforge.net)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
* * 4. The name "JasperReports" must not be used to endorse or promote products * derived from this software without prior written permission. For written * permission, please contact teodord@users.sourceforge.net.
* * 5. Products derived from this software may not be called "JasperReports", nor * may "JasperReports" appear in their name, without prior written permission
* of Teodor Danciu.
* * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/*
* ============================================================================
* GNU Lesser General Public License
* ============================================================================
*
* JasperReports - Free Java report-generating library.
* Copyright (C) 2001-2004 Teodor Danciu teodord@users.sourceforge.net
* * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
* * Teodor Danciu
* 173, Calea Calarasilor, Bl. 42, Sc. 1, Ap. 18
* Postal code 030615, Sector 3
* Bucharest, ROMANIA
* Email: teodord@users.sourceforge.net
*/
import dori.jasper.engine.*;
import dori.jasper.engine.data.*;
import dori.jasper.engine.design.*;
import dori.jasper.engine.export.*;
import dori.jasper.engine.util.*;
import dori.jasper.view.*;
import java.sql.*;
import java.awt.*;
import java.util.*;
import java.io.*;


/**
*
*/
public class NoXmlDesignApp
{


/**
*
*/
private static final String TASK_COMPILE = "compile";
private static final String TASK_FILL = "fill";
private static final String TASK_PRINT = "print";
private static final String TASK_PDF = "pdf";
private static final String TASK_XML = "xml";
private static final String TASK_XML_EMBED = "xmlEmbed";
private static final String TASK_HTML = "html";
private static final String TASK_XLS = "xls";
private static final String TASK_CSV = "csv";
private static final String TASK_RUN = "run";
private static final String TASK_WRITE_XML = "writeXml";


/**
*
*/
public static void main(String[] args)
{
String fileName = null;
String taskName = null;

if(args.length == 0)
{
usage();
return;
}

int k = 0;
while ( args.length > k )
{
if ( args[k].startsWith("-T"«») )
taskName = args[k].substring(2);
if ( args[k].startsWith("-F"«») )
fileName = args[k].substring(2);

k++;
}

try
{
long start = System.currentTimeMillis();
if (TASK_COMPILE.equals(taskName))
{
JasperDesign jasperDesign = getJasperDesign();
JasperCompileManager.compileReportToFile(jasperDesign, fileName);
System.err.println("Compile time : " + (System.currentTimeMillis() - start));
System.exit(0);
}
else if (TASK_FILL.equals(taskName))
{
//Preparing parameters
Map parameters = new HashMap();
parameters.put("ReportTitle", "Address Report"«»);
parameters.put("OrderByClause", "ORDER BY City"«»);

JasperFillManager.fillReportToFile(fileName, parameters, getConnection());
System.err.println("Filling time : " + (System.currentTimeMillis() - start));
System.exit(0);
}
else if (TASK_PRINT.equals(taskName))
{
JasperPrintManager.printReport(fileName, true);
System.err.println("Printing time : " + (System.currentTimeMillis() - start));
System.exit(0);
}
else if (TASK_PDF.equals(taskName))
{
JasperExportManager.exportReportToPdfFile(fileName);
System.err.println("PDF creation time : " + (System.currentTimeMillis() - start));
System.exit(0);
}
else if (TASK_XML.equals(taskName))
{
JasperExportManager.exportReportToXmlFile(fileName, false);
System.err.println("XML creation time : " + (System.currentTimeMillis() - start));
System.exit(0);
}
else if (TASK_XML_EMBED.equals(taskName))
{
JasperExportManager.exportReportToXmlFile(fileName, true);
System.err.println("XML creation time : " + (System.currentTimeMillis() - start));
System.exit(0);
}
else if (TASK_HTML.equals(taskName))
{
JasperExportManager.exportReportToHtmlFile(fileName);
System.err.println("HTML creation time : " + (System.currentTimeMillis() - start));
System.exit(0);
}
else if (TASK_XLS.equals(taskName))
{
File sourceFile = new File(fileName);

JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile);

File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xls"«»);

JRXlsExporter exporter = new JRXlsExporter();

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString());
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);

exporter.exportReport();

System.err.println("XLS creation time : " + (System.currentTimeMillis() - start));
System.exit(0);
}
else if (TASK_CSV.equals(taskName))
{
File sourceFile = new File(fileName);

JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile);

File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv"«»);

JRCsvExporter exporter = new JRCsvExporter();

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString());

exporter.exportReport();

System.err.println("CSV creation time : " + (System.currentTimeMillis() - start));
System.exit(0);
}
else if (TASK_RUN.equals(taskName))
{
//Preparing parameters
Map parameters = new HashMap();
parameters.put("ReportTitle", "Address Report"«»);
parameters.put("OrderByClause", "ORDER BY City"«»);

JasperRunManager.runReportToPdfFile(fileName, parameters, getConnection());
System.err.println("PDF running time : " + (System.currentTimeMillis() - start));
System.exit(0);
}
else if (TASK_WRITE_XML.equals(taskName))
{
JasperCompileManager.writeReportToXmlFile(fileName);
System.err.println("XML design creation time : " + (System.currentTimeMillis() - start));
System.exit(0);
}
else
{
usage();
System.exit(0);
}
}
catch (JRException e)
{
e.printStackTrace();
System.exit(1);
}
catch (Exception e)
{
e.printStackTrace();
System.exit(1);
}
}


/**
*
*/
private static void usage()
{
System.out.println( "NoXmlDesignApp usage:" );
System.out.println( "tjava NoXmlDesignApp -Ttask -Ffile" );
System.out.println( "tTasks : compile | fill | print | pdf | xml | xmlEmbed | html | xls | csv | run | writeXml" );
}


/**
*
*/
private static Connection getConnection() throws ClassNotFoundException, SQLException
{
//Change these settings according to your local configuration
String driver = "org.hsqldb.jdbcDriver";
String connectString = "jdbc:hsqldb:hsql://localhost";
String user = "sa";
String password = "";


Class.forName(driver);
Connection conn = DriverManager.getConnection(connectString, user, password);
return conn;
}


/**
*
*/
private static JasperDesign getJasperDesign() throws JRException
{
//JasperDesign
JasperDesign jasperDesign = new JasperDesign();
jasperDesign.setName("NoXmlDesignReport"«»);
jasperDesign.setPageWidth(595);
jasperDesign.setPageHeight(842);
jasperDesign.setColumnWidth(515);
jasperDesign.setColumnSpacing(0);
jasperDesign.setLeftMargin(40);
jasperDesign.setRightMargin(40);
jasperDesign.setTopMargin(50);
jasperDesign.setBottomMargin(50);

//Fonts
JRDesignReportFont normalFont = new JRDesignReportFont();
normalFont.setName("Arial_Normal"«»);
normalFont.setDefault(true);
normalFont.setFontName("Arial"«»);
normalFont.setSize(12);
normalFont.setPdfFontName("Helvetica"«»);
normalFont.setPdfEncoding("Cp1252"«»);
normalFont.setPdfEmbedded(false);
jasperDesign.addFont(normalFont);

JRDesignReportFont boldFont = new JRDesignReportFont();
boldFont.setName("Arial_Bold"«»);
boldFont.setDefault(false);
boldFont.setFontName("Arial"«»);
boldFont.setSize(12);
boldFont.setBold(true);
boldFont.setPdfFontName("Helvetica-Bold"«»);
boldFont.setPdfEncoding("Cp1252"«»);
boldFont.setPdfEmbedded(false);
jasperDesign.addFont(boldFont);

JRDesignReportFont italicFont = new JRDesignReportFont();
italicFont.setName("Arial_Italic"«»);
italicFont.setDefault(false);
italicFont.setFontName("Arial"«»);
italicFont.setSize(12);
italicFont.setItalic(true);
italicFont.setPdfFontName("Helvetica-Oblique"«»);
italicFont.setPdfEncoding("Cp1252"«»);
italicFont.setPdfEmbedded(false);
jasperDesign.addFont(italicFont);

//Parameters
JRDesignParameter parameter = new JRDesignParameter();
parameter.setName("ReportTitle"«»);
parameter.setValueClass(java.lang.String.class);
jasperDesign.addParameter(parameter);

parameter = new JRDesignParameter();
parameter.setName("OrderByClause"«»);
parameter.setValueClass(java.lang.String.class);
jasperDesign.addParameter(parameter);

//Query
JRDesignQuery query = new JRDesignQuery();
query.setText("SELECT * FROM Address $P!{OrderByClause}"«»);
jasperDesign.setQuery(query);

//Fields
JRDesignField field = new JRDesignField();
field.setName("Id"«»);
field.setValueClass(java.lang.Integer.class);
jasperDesign.addField(field);

field = new JRDesignField();
field.setName("FirstName"«»);
field.setValueClass(java.lang.String.class);
jasperDesign.addField(field);

field = new JRDesignField();
field.setName("LastName"«»);
field.setValueClass(java.lang.String.class);
jasperDesign.addField(field);

field = new JRDesignField();
field.setName("Street"«»);
field.setValueClass(java.lang.String.class);
jasperDesign.addField(field);

field = new JRDesignField();
field.setName("City"«»);
field.setValueClass(java.lang.String.class);
jasperDesign.addField(field);

//Variables
JRDesignVariable variable = new JRDesignVariable();
variable.setName("CityNumber"«»);
variable.setValueClass(java.lang.Integer.class);
variable.setResetType(JRVariable.RESET_TYPE_GROUP);
JRDesignGroup group = new JRDesignGroup();
group.setName("CityGroup"«»);
variable.setResetGroup(group);
variable.setCalculation(JRVariable.CALCULATION_SYSTEM);
JRDesignExpression expression = new JRDesignExpression();
expression.setValueClass(java.lang.Integer.class);
expression.setText("($V{CityNumber} != null)?(new Integer($V{CityNumber}.intValue() + 1)):«»(new Integer(1))"«»);
variable.setInitialValueExpression(expression);
jasperDesign.addVariable(variable);

variable = new JRDesignVariable();
variable.setName("AllCities"«»);
variable.setValueClass(java.lang.String.class);
variable.setResetType(JRVariable.RESET_TYPE_REPORT);
variable.setCalculation(JRVariable.CALCULATION_SYSTEM);
jasperDesign.addVariable(variable);

//Groups
group.setMinHeightToStartNewPage(60);
expression = new JRDesignExpression();
expression.setValueClass(java.lang.String.class);
expression.setText("$F{City}"«»);
group.setExpression(expression);

JRDesignBand band = new JRDesignBand();
band.setHeight(20);
JRDesignRectangle rectangle = new JRDesignRectangle();
rectangle.setX(0);
rectangle.setY(4);
rectangle.setWidth(515);
rectangle.setHeight(15);
rectangle.setForecolor(new Color(0xC0, 0xC0, 0xC0));
rectangle.setBackcolor(new Color(0xC0, 0xC0, 0xC0));
rectangle.setStretchType(JRGraphicElement.STRETCH_TYPE_NO_STRETCH);
band.addElement(rectangle);
JRDesignTextField textField = new JRDesignTextField();
textField.setX(0);
textField.setY(4);
textField.setWidth(515);
textField.setHeight(15);
textField.setBackcolor(new Color(0xC0, 0xC0, 0xC0));
textField.setMode(JRElement.MODE_OPAQUE);
textField.setTextAlignment(JRTextElement.TEXT_ALIGN_LEFT);
textField.setFont(boldFont);
expression = new JRDesignExpression();
expression.setValueClass(java.lang.String.class);
expression.setText("" " + String.valueOf($V{CityNumber}) + ". " + String.valueOf($F{City})"«»);
textField.setExpression(expression);
band.addElement(textField);
JRDesignLine line = new JRDesignLine();
line.setX(0);
line.setY(19);
line.setWidth(515);
line.setHeight(0);
band.addElement(line);
group.setGroupHeader(band);

band = new JRDesignBand();
band.setHeight(20);
line = new JRDesignLine();
line.setX(0);
line.setY(-1);
line.setWidth(515);
line.setHeight(0);
band.addElement(line);
JRDesignStaticText staticText = new JRDesignStaticText();
staticText.setX(400);
staticText.setY(0);
staticText.setWidth(60);
staticText.setHeight(15);
staticText.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);
staticText.setFont(boldFont);
staticText.setText("Count : "«»);
band.addElement(staticText);
textField = new JRDesignTextField();
textField.setX(460);
textField.setY(0);
textField.setWidth(30);
textField.setHeight(15);
textField.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);
textField.setFont(boldFont);
expression = new JRDesignExpression();
expression.setValueClass(java.lang.Integer.class);
expression.setText("$V{CityGroup_COUNT}"«»);
textField.setExpression(expression);
band.addElement(textField);
group.setGroupFooter(band);

jasperDesign.addGroup(group);

//Title
band = new JRDesignBand();
band.setHeight(50);
line = new JRDesignLine();
line.setX(0);
line.setY(0);
line.setWidth(515);
line.setHeight(0);
band.addElement(line);
textField = new JRDesignTextField();
textField.setBlankWhenNull(true);
textField.setX(0);
textField.setY(10);
textField.setWidth(515);
textField.setHeight(30);
textField.setTextAlignment(JRTextElement.TEXT_ALIGN_CENTER);
JRDesignReportFont bigFont = new JRDesignReportFont();
bigFont.setName("Arial_Normal"«»);
bigFont.setDefault(true);
bigFont.setFontName("Arial"«»);
bigFont.setSize(22);
bigFont.setPdfFontName("Helvetica"«»);
bigFont.setPdfEncoding("Cp1252"«»);
bigFont.setPdfEmbedded(false);
textField.setFont(bigFont);
expression = new JRDesignExpression();
expression.setValueClass(java.lang.String.class);
expression.setText("$P{ReportTitle}"«»);
textField.setExpression(expression);
band.addElement(textField);
jasperDesign.setTitle(band);

//Page header
band = new JRDesignBand();
band.setHeight(20);
rectangle = new JRDesignRectangle();
rectangle.setX(0);
rectangle.setY(5);
rectangle.setWidth(515);
rectangle.setHeight(15);
rectangle.setForecolor(new Color(0x33, 0x33, 0x33));
rectangle.setBackcolor(new Color(0x33, 0x33, 0x33));
band.addElement(rectangle);
staticText = new JRDesignStaticText();
staticText.setX(0);
staticText.setY(5);
staticText.setWidth(55);
staticText.setHeight(15);
staticText.setForecolor(Color.white);
staticText.setBackcolor(new Color(0x33, 0x33, 0x33));
staticText.setMode(JRElement.MODE_OPAQUE);
staticText.setTextAlignment(JRTextElement.TEXT_ALIGN_CENTER);
staticText.setFont(boldFont);
staticText.setText("ID"«»);
band.addElement(staticText);
staticText = new JRDesignStaticText();
staticText.setX(55);
staticText.setY(5);
staticText.setWidth(205);
staticText.setHeight(15);
staticText.setForecolor(Color.white);
staticText.setBackcolor(new Color(0x33, 0x33, 0x33));
staticText.setMode(JRElement.MODE_OPAQUE);
staticText.setFont(boldFont);
staticText.setText("Name"«»);
band.addElement(staticText);
staticText = new JRDesignStaticText();
staticText.setX(260);
staticText.setY(5);
staticText.setWidth(255);
staticText.setHeight(15);
staticText.setForecolor(Color.white);
staticText.setBackcolor(new Color(0x33, 0x33, 0x33));
staticText.setMode(JRElement.MODE_OPAQUE);
staticText.setFont(boldFont);
staticText.setText("Street"«»);
band.addElement(staticText);
jasperDesign.setPageHeader(band);

//Column header
band = new JRDesignBand();
jasperDesign.setColumnHeader(band);

//Detail
band = new JRDesignBand();
band.setHeight(20);
textField = new JRDesignTextField();
textField.setX(0);
textField.setY(4);
textField.setWidth(50);
textField.setHeight(15);
textField.setTextAlignment(JRTextElement.TEXT_ALIGN_RIGHT);
textField.setFont(normalFont);
expression = new JRDesignExpression();
expression.setValueClass(java.lang.Integer.class);
expression.setText("$F{Id}"«»);
textField.setExpression(expression);
band.addElement(textField);
textField = new JRDesignTextField();
textField.setStretchWithOverflow(true);
textField.setX(55);
textField.setY(4);
textField.setWidth(200);
textField.setHeight(15);
textField.setPositionType(JRElement.POSITION_TYPE_FLOAT);
textField.setFont(normalFont);
expression = new JRDesignExpression();
expression.setValueClass(java.lang.String.class);
expression.setText("$F{FirstName} + " " + $F{LastName}"«»);
textField.setExpression(expression);
band.addElement(textField);
textField = new JRDesignTextField();
textField.setStretchWithOverflow(true);
textField.setX(260);
textField.setY(4);
textField.setWidth(255);
textField.setHeight(15);
textField.setPositionType(JRElement.POSITION_TYPE_FLOAT);
textField.setFont(normalFont);
expression = new JRDesignExpression();
expression.setValueClass(java.lang.String.class);
expression.setText("$F{Street}"«»);
textField.setExpression(expression);
band.addElement(textField);
line = new JRDesignLine();
line.setX(0);
line.setY(19);
line.setWidth(515);
line.setHeight(0);
line.setForecolor(new Color(0x80, 0x80, 0x80));
line.setPositionType(JRElement.POSITION_TYPE_FLOAT);
band.addElement(line);
jasperDesign.setDetail(band);

//Column footer
band = new JRDesignBand();
jasperDesign.setColumnFooter(band);

//Page footer
band = new JRDesignBand();
jasperDesign.setPageFooter(band);

//Summary
band = new JRDesignBand();
jasperDesign.setSummary(band);

return jasperDesign;
}
}
Link to comment
Share on other sites

  • 3 months later...

Hi guys, I'm new at java and jasper. I have created reports using JasperReports and iReport but have to make my reports more dynamic. Users should be able to select columns that should appear on report.

I have tried going thru the article- http://www.ibm.com/developerworks/websphere/library/techarticles/0505_olivieri/0505_olivieri.html

but have an error that reads - identify expected at this line :- BufferedWriter writer = new BufferedWriter(new, OutputStreamWriter(outStream));

here is the complete code:

import org.apache.velocity.Template;

import org.apache.velocity.app.Velocity;

import org.apache.velocity.context.Context;

import org.apache.velocity.exception.ParseErrorException;

import org.apache.velocity.exception.ResourceNotFoundException;

import org.apache.velocity.servlet.VelocityServlet;

import java.io.BufferedWriter;

import java.io.PipedInputStream;

import java.io.PipedOutputStream;

 

 

 

import javax.servlet.ServletConfig;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import java.util.Properties;

public class VelocityTest extends VelocityServlet {

protected Properties loadConfiguration(ServletConfig config) {

Properties properties = new Properties();

properties.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, config.getServletContext().getRealPath("/"));

 

return properties;

}

 

public Template handleRequest(HttpServletRequest request, HttpServletResponse response, Context context) {

context.put("sql","SELECT * from wcs.tblpayments");

String fieldList[] = {"PAYMENT_NO","WCS_NUMBER","CONTRACT_NO","PAYMENT_INDICATOR","DIVISION_CODE","BENEFICIARY_CODE","ADVICE_NUMBER"};

context.put("title","testing Velocity");

context.put("$headerString","HEADER");

context.put("fieldList",fieldList);

Template template = null;

PipedInputStream inStream;

BufferedWriter writer ;

Thread thread;

PipedOutputStream outStream;

TemplateCompiler compiler;

try {

PipedOutputStream outStream = new PipedOutputStream();

 

BufferedWriter writer = new BufferedWriter(new, OutputStreamWriter(outStream));

 

 

// Connect input stream to output stream

inStream = new PipedInputStream(outStream);

compiler = new TemplateCompiler(inStream);

thread = new Thread(compiler);

thread.start();

template.merge(context, writer);

tpl = getTemplate("BasicReport.vm");

 

// tpl = getTemplate("hello.vm");

} catch (ResourceNotFoundException e) {

e.printStackTrace();

} catch (ParseErrorException e) {

e.printStackTrace();

} catch (Exception e) {

e.printStackTrace();

} finally {

if (writer != null) {

writer.flush();

writer.close();

}

}

thread.join();

// Get compiled report

return (compiler.getJasperReport());

}

 

 

}

 

 

any assistance will be greatly appreciated

Link to comment
Share on other sites

hi

im having the same problem an facing the same situation.i only started using jasper early this year.so i sumtyms find problems getting around.

 

how do 1 use this class.

i looked at the sample application distributed with jasperreports but i can seem to find my way around this.

pls help.im using tomcat 5.5 netbeans,(ireports)

 

where do i need to start.

i've looked at the ibm application tutorial but i cant seem to get there.

 

pls assist with other tutorial or help me get there

Link to comment
Share on other sites

If you are trying to dynamically display a report for an arbitrary JDBC result, I would take the velocity approach.

 

Execute the query

Pass the ResultSetMetaData ($meta) to the VelocityEngine

Iterate the columns to build your dynamic components

 

Code:

#foreach($i in [1..$meta.columnCount])
<field name="${meta.getColumnName( $i )}" class="java.lang.String"/>
#end

 

Do the same with your static text ($meta.getColumnLabel($i)) in your header and text fields (\$F{$meta.getColumnName($i)}) in your detail bands.

 

Dynamically building a report definition requires a fairly deep understanding of the report structure, so if you have not already done so, I recommend getting the ultimate guide.

* Pro can be done with just objects

* Con requires velocity setup.

 

 

You could also generate an XML representaion of the ResultSetMetaData and process it with an XSL template that has the desired report structure.

* Pro can be done with basic jvm1.4+

* Con requires intermediary xml step.

Post edited by: gbegley, at: 2007/08/14 15:42

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...