Skip to main content



      Home
Home » Archived » BIRT » Generating BIRT report from Java/JSP application
Generating BIRT report from Java/JSP application [message #188570] Thu, 31 August 2006 08:14 Go to next message
Eclipse UserFriend
I am working on an Java(jsp)/JBoss/SqlServer application that will be used
entirely in house and would like to use BIRT to generate pre-designed
reports that the user can run using a button on the GUI(jsp button click
event) and see the appropriate records. The SQL is already generated in
the application.

I have installed BIRT and the Eclipse plug-in. I was able to generate a
basic report, set a data link and display the report from within Eclipse.
There are two things I still need to accomplish which are very closely
related and I am having difficulties solving them.

1. Running the pre-created report from the Java code. I was thinking of
generating a PDF so it could be saved and easily shared with other people
through email. I would like to avoid deploying out to a web server if at
all possible. I just want to the user to click the "view" button and have
the application generate a PDF based onthat they can then save, print or
do whatever they want with it.

2. When the user clicks the view button I want to generate the report with
the proper data using the logic of the program flow to determine what the
user wants. As I mentioned I am already hitting the database to display
the record in a JTable. All I need to do is generate the report with the
same data.

I have searched around and I only find information on creating web pages
or viewing from eclipse. Any direction or advice would be greatly
appreciated.
Re: Generating BIRT report from Java/JSP application [message #188578 is a reply to message #188570] Thu, 31 August 2006 08:37 Go to previous messageGo to next message
Eclipse UserFriend
hi manuel,

For running BIRT with your server you should configure the birt-runtime.
so download the following file and follow the steps
birt-runtime-version.zip

regards,
Guru.
Re: Generating BIRT report from Java/JSP application [message #188593 is a reply to message #188578] Thu, 31 August 2006 08:49 Go to previous messageGo to next message
Eclipse UserFriend
Hi gurumoothy,

Thanks for responding for my query.

I have downloaded the birt-runtime and put the plugin and configuration
folders in the buildpath of eclispe since i'm using eclipse to deploy my
appln.
but when i click the button(jsp button action) for calling a java file,
i'm getting a null pointer exception since my platform is not yet started.
This is my java code..

------------------------------------------------------------ -------

package com.bmw.bbemails.test;


import java.util.HashMap;
import java.util.logging.Level;

import javax.servlet.*;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.core.framework.IPlatformContext;
import org.eclipse.birt.core.framework.PlatformServletContext;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineConstants;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.report.engine.api.HTMLActionHandler;
import org.eclipse.birt.report.engine.api.HTMLEmitterConfig;
import org.eclipse.birt.report.engine.api.HTMLRenderContext;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.impl.ReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;/*
*/
public class Test {

public void test() throws EngineException
{

HashMap<String, Integer> parameters = new HashMap<String, Integer>();

String name = "Top Count";
Integer pvalue = new Integer(4);
parameters.put(name, pvalue);

IReportEngine engine=null;
EngineConfig config = null;

try{

config = new EngineConfig( );
config.setEngineHome(
"K:/eclipse_projects/bbemails/web/WEB-INF/lib/plugins" );

config.setLogConfig("s:/birt/logs", Level.FINE);

Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform

createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_EN GINE_FACTORY
);
engine = factory.createReportEngine(config);
engine.changeLogLevel( Level.WARNING );


}catch( Exception ex){
ex.printStackTrace();
}


IReportRunnable design = null;

//Open the report design
design =
engine.openReportDesign("K:/eclipse_projects/bbemails/web/Report.rptdesign ");

//Create task to run and render the report,
IRunAndRenderTask task = engine.createRunAndRenderTask(design);


//Set Render context to handle url and image locataions
HTMLRenderContext renderContext = new HTMLRenderContext();
//Set the Base URL for all actions
renderContext.setBaseURL("http://localhost:8080/bbemails/");
//Tell the Engine to prepend all images with this URL - Note this
requires using the HTMLServerImageHandler
renderContext.setBaseImageURL("http://localhost:8080/bbemails/web");
//Tell the Engine where to write the images to
renderContext.setImageDirectory("s:/birt/logs");
//Tell the Engine what image formats are supported. Note you must have
SVG in the string
//to render charts in SVG.
renderContext.setSupportedImageFormats("JPG;PNG;BMP;SVG");
HashMap<String, HTMLRenderContext> contextMap = new HashMap<String,
HTMLRenderContext>();
contextMap.put( EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT,
renderContext );
task.setAppContext( contextMap );
//Set parameters for the report
task.setParameterValues(parameters);
//Alternatively set each seperately
//task.setParameterValue("Top Count", new Integer(12));
task.validateParameters();

//Add a scriptable object, which will allow the report developer to put
//script in the report that references this Java object. eg in script
//pFilter.myjavamethod()
//ProcessFilter pf = new ProcessFilter();
//task.addScriptableJavaObject("pFilter", pf);

//Set rendering options - such as file or stream output,
//output format, whether it is embeddable, etc
HTMLRenderOption options = new HTMLRenderOption();

//Remove HTML and Body tags
options.setEmbeddable(true);

//Set ouptut location
options.setOutputFileName("s:/birt/logs");

//Set output format
options.setOutputFormat("html");
task.setRenderOption(options);

//run the report and destroy the engine
//Note - If the program stays resident do not shutdown the Platform or
the Engine
task.run();
task.close();
engine.shutdown();
Platform.shutdown();
System.out.println("Finished");
}
/**
* @param args
*/
public static void main(String[] args) {
try
{
}
catch ( Exception e )
{
e.printStackTrace();
}
}

}


------------------------------------------------------------ -------------

if this is not the correct way, could u please help me solve this problem?

Regards,

manuel
Re: Generating BIRT report from Java/JSP application [message #188684 is a reply to message #188593] Thu, 31 August 2006 09:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eldude23.hotmail.com

I had a similar problem... if you (as I did) copied your ReportEngine
directory to "X:/..../lib", try changing...

config.setEngineHome(
"K:/eclipse_projects/bbemails/web/WEB-INF/lib/plugins" );

to

config.setEngineHome( "K:/eclipse_projects/bbemails/web/WEB-INF/lib" );


Roger


"Manuel" <usha.manuel@mybdr.com> wrote in message
news:150a27075c6c0eca22868d356ec8bf4c$1@www.eclipse.org...
> Hi gurumoothy,
>
> Thanks for responding for my query.
>
> I have downloaded the birt-runtime and put the plugin and configuration
> folders in the buildpath of eclispe since i'm using eclipse to deploy my
> appln.
> but when i click the button(jsp button action) for calling a java file,
> i'm getting a null pointer exception since my platform is not yet started.
> This is my java code..
>
> ------------------------------------------------------------ -------
>
> package com.bmw.bbemails.test;
>
>
> import java.util.HashMap;
> import java.util.logging.Level;
>
> import javax.servlet.*;
> import org.eclipse.birt.core.framework.Platform;
> import org.eclipse.birt.core.framework.IPlatformContext;
> import org.eclipse.birt.core.framework.PlatformServletContext;
> import org.eclipse.birt.report.engine.api.EngineConfig;
> import org.eclipse.birt.report.engine.api.EngineConstants;
> import org.eclipse.birt.report.engine.api.EngineException;
> import org.eclipse.birt.core.exception.BirtException;
> import org.eclipse.birt.report.engine.api.HTMLActionHandler;
> import org.eclipse.birt.report.engine.api.HTMLEmitterConfig;
> import org.eclipse.birt.report.engine.api.HTMLRenderContext;
> import org.eclipse.birt.report.engine.api.HTMLRenderOption;
> import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;
> import org.eclipse.birt.report.engine.api.IReportEngine;
> import org.eclipse.birt.report.engine.api.IReportEngineFactory;
> import org.eclipse.birt.report.engine.api.impl.ReportEngineFactory;
> import org.eclipse.birt.report.engine.api.IReportRunnable;
> import org.eclipse.birt.report.engine.api.IRunAndRenderTask;/*
> */
> public class Test {
>
> public void test() throws EngineException
> {
>
> HashMap<String, Integer> parameters = new HashMap<String, Integer>();
>
> String name = "Top Count";
> Integer pvalue = new Integer(4);
> parameters.put(name, pvalue);
>
> IReportEngine engine=null;
> EngineConfig config = null;
>
> try{
> config = new EngineConfig( );
> config.setEngineHome(
> "K:/eclipse_projects/bbemails/web/WEB-INF/lib/plugins" );
>
> config.setLogConfig("s:/birt/logs", Level.FINE);
> Platform.startup( config );
> IReportEngineFactory factory = (IReportEngineFactory) Platform
>
> createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_EN GINE_FACTORY );
> engine = factory.createReportEngine(config);
> engine.changeLogLevel( Level.WARNING );
> }catch( Exception ex){
> ex.printStackTrace();
> }
>
>
> IReportRunnable design = null;
>
> //Open the report design
> design =
> engine.openReportDesign("K:/eclipse_projects/bbemails/web/Report.rptdesign ");
> //Create task to run and render the report,
> IRunAndRenderTask task = engine.createRunAndRenderTask(design);
>
> //Set Render context to handle url and image locataions
> HTMLRenderContext renderContext = new HTMLRenderContext();
> //Set the Base URL for all actions
> renderContext.setBaseURL("http://localhost:8080/bbemails/");
> //Tell the Engine to prepend all images with this URL - Note this requires
> using the HTMLServerImageHandler
> renderContext.setBaseImageURL("http://localhost:8080/bbemails/web");
> //Tell the Engine where to write the images to
> renderContext.setImageDirectory("s:/birt/logs");
> //Tell the Engine what image formats are supported. Note you must have
> SVG in the string //to render charts in SVG.
> renderContext.setSupportedImageFormats("JPG;PNG;BMP;SVG");
> HashMap<String, HTMLRenderContext> contextMap = new HashMap<String,
> HTMLRenderContext>();
> contextMap.put( EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT,
> renderContext );
> task.setAppContext( contextMap );
> //Set parameters for the report
> task.setParameterValues(parameters);
> //Alternatively set each seperately
> //task.setParameterValue("Top Count", new Integer(12));
> task.validateParameters();
>
> //Add a scriptable object, which will allow the report developer to put
> //script in the report that references this Java object. eg in script
> //pFilter.myjavamethod()
> //ProcessFilter pf = new ProcessFilter();
> //task.addScriptableJavaObject("pFilter", pf);
>
> //Set rendering options - such as file or stream output, //output format,
> whether it is embeddable, etc
> HTMLRenderOption options = new HTMLRenderOption();
>
> //Remove HTML and Body tags
> options.setEmbeddable(true);
>
> //Set ouptut location
> options.setOutputFileName("s:/birt/logs");
>
> //Set output format
> options.setOutputFormat("html");
> task.setRenderOption(options);
>
> //run the report and destroy the engine
> //Note - If the program stays resident do not shutdown the Platform or the
> Engine
> task.run();
> task.close();
> engine.shutdown();
> Platform.shutdown();
> System.out.println("Finished");
> } /**
> * @param args
> */
> public static void main(String[] args) {
> try
> {
> }
> catch ( Exception e )
> {
> e.printStackTrace();
> }
> }
>
> }
>
>
> ------------------------------------------------------------ -------------
>
> if this is not the correct way, could u please help me solve this problem?
>
> Regards,
>
> manuel
>
>
Re: Generating BIRT report from Java/JSP application [message #188691 is a reply to message #188684] Thu, 31 August 2006 10:24 Go to previous message
Eclipse UserFriend
Thanks roger itz now working fine :-) .. but there exists some problem
with data connection..
Previous Topic:Charting, several issues
Next Topic:Highlighting odd rows
Goto Forum:
  


Current Time: Mon Jul 21 21:38:11 EDT 2025

Powered by FUDForum. Page generated in 0.05292 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top