Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Newbie: report with parameters
Avinoam
<p>Hi,</p><p> </p><p>I am a newbie to Birt. I need to do the following:</p><p> </p><p>1. Create a report that accepts certain parameters.</p><p>2. The data source of a report is a Java function</p><p>3. The creation of the report needs to be executed from Command Line of (BETTER) from Java Spring scheduling.</p><p> </p><p>Any ideas? Sample would be HIGHLY appreciated.</p><p> </p><p>Thanks a lot,</p><p> </p><p>Avi.</p>
Find more posts tagged with
Comments
kclark
<p>What version of BIRT are you using? In 4.3.x you can create a POJO as a data source. Or you can create a scripted data source if a POJO is too much for what you're needing. As for question #3 are you wanting to render the report from Java or design the report with it?</p>
Avinoam
<p>Hi,</p><p> </p><p>Thanks for your reply. I am using v4.3.1. </p><p>I would like to create a simple report, all it has are graphs with labels. But this report has to be created on the fly because graphs are displayed based on user selections.</p><p> </p><p>So basically I need a sample code to:</p><p> </p><p>1. Create a report</p><p>2. Add graphs to the report</p><p>3. Populate the graphs with some data.</p><p>4. Export the report as PDF/Excel.</p><p> </p><p>If you can help here that would be very highly appreciated.</p><p> </p><p>Thanks a lot!</p><p> </p><p>Avi</p>
fmakwsi
<p>Here is an Example for HTML Export with parameters: </p><pre class="_prettyXprint _lang-js">
@Override
public final String getHTMLString(final String param) { ByteArrayOutputStream htmlOutputStream = new ByteArrayOutputStream(); HTMLRenderOption renderOptions = new HTMLRenderOption(); renderOptions.setOutputFormat(HTMLRenderOption.HTML); renderOptions.setOutputStream(htmlOutputStream); renderOptions.setEmbeddable(true); try { runReport(renderOptions, param); } catch (Exception e) { getLogger().error(e.getMessage(), e); } String htmlString = null; try { htmlString = htmlOutputStream.toString("UTF-8"); } catch (Exception e) { getLogger().error(e.getMessage(), e); } return htmlString; }</pre><pre class="_prettyXprint _lang-js"> private void runReport(final HTMLRenderOption renderOptions, final String param) { IReportEngine engine = null; EngineConfig config = null; IRunAndRenderTask task = null; try { config = new EngineConfig(); config.setLogConfig(null, Level.OFF); HashMap<String, ClassLoader> map = config.getAppContext(); map.put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, CompanyData.class.getClassLoader()); // includes the class into the birt classpath by adding it to the // config for the birt engine config.setAppContext(map); Platform.startup(config); final IReportEngineFactory factory = (IReportEngineFactory) Platform .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY); engine = factory.createReportEngine(config); final IReportRunnable design = engine.openReportDesign(REPORT_FILE_PATH); task = engine.createRunAndRenderTask(design); // only use parameter if one is set if (param != null && !param.isEmpty()) { task.setParameterValue("FilterName", param); task.validateParameters(); } else { task.setParameterValue("FilterName", ""); task.validateParameters(); } task.setRenderOption(renderOptions); task.run(); } catch (Exception e) { getLogger().error(e.getMessage(), e); } finally { if (task != null) { task.close(); } if (engine != null) { engine.destroy(); } Platform.shutdown(); } }</pre><p>You just got to use PDFRenderOption instead of HTMLRenderOption and need to call setOutputFileName() to save it as a file. Thats not necessary in my case because i just need a HTML String. Hope i got help ya</p><p> </p><p>Take a look on <a data-ipb='nomediaparse' href='
http://wiki.eclipse.org/Simple_Execute_(BIRT)_2.1'>http://wiki.eclipse.org/Simple_Execute_(BIRT)_2.1</a> for
more information. you'll simply get moar informations if you just google "execute report BIRT"</p>
Avinoam
<p>Thanks!</p>
fmakwsi
<p>No prob, feel free to ask again. </p><p> </p><p>Btw i set no ImageHandler, or ImageDirectory in that case because there are no Images to display, if your report got charts etc. you need to set those i think</p>