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)
Generating a OutputStream using HTMLRenderOption
simteq
<p>Hi, I am trying to embed a BIRT report into an existing JSF/Richfaces project using BIRT Runtime 4.4.1 but for some reason the output only includes the Header and Footer from the report plus one table column header. The data and most of the table headers do not get included.</p>
<pre class="_prettyXprint">
status = "Starting Platform";
EngineConfig engineConfig = new EngineConfig();
Platform.startup( engineConfig );
status = "Create Engine";
IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
IReportEngine engine = factory.createReportEngine( engineConfig );
status = "Create Report Runnable";
IReportRunnable runnable = engine.openReportDesign( reportName );
IRunAndRenderTask task = engine.createRunAndRenderTask( runnable );
IGetParameterDefinitionTask definitionTask = engine.createGetParameterDefinitionTask(runnable);
definitionTask.evaluateDefaults();
status = "Set Parameters";
HashMap<String, Object> params = definitionTask.getDefaultValues();
params.put("p_customer_internal_ref", selectedCustomer);
task.getAppContext().put("OdaJDBCDriverPassInConnection", jdbcTemplate.getDataSource().getConnection());
ByteArrayOutputStream bout = new ByteArrayOutputStream();
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFormat("html");
options.setOutputStream(bout);
task.setRenderOption(options);
task.setParameterValues(params);
task.run();
customerFacilities = bout.toString();
</pre>
<p>The customerFacilities is displayed using:</p>
<pre class="_prettyXprint">
<h:outputText id="customerFacilitiesReport" value="#{reportBean.customerFacilities}" escape="false" />
</pre>
<p>The report itself was designed using Eclipse downloaded from the BIRT website and works perfectly when viewed via Eclipse.</p>
<p> </p>
<p>Any help would be appreciated</p>
Find more posts tagged with
Comments
simteq
<p>Hi, just a thought on this, the line of code :</p>
<pre class="_prettyXprint">
task.getAppContext().put("OdaJDBCDriverPassInConnection", jdbcTemplate.getDataSource().getConnection());
</pre>
<p>I am using a standard JDBC connection to an Oracle Database so is the string OdaJDBCDriverPassInConnection correct, the second parameter is a java.sql.Connection</p>
simteq
<p>Hi, I have got this sorted but as I had a lot of trouble finding good documentation etc I will try and include some detail here:</p>
<p> </p>
<p>Report designed in Eclipse with Report Designer</p>
<p>Using BIRT Runtime 4.4.1, JSF, Richfaces running in Tomcat v6.</p>
<p> </p>
<p>The aim to embed a report into an existing JSF page where a customer is selected from a list derived from on Oracle DB, this customer is then passed as a parameter to the report query.</p>
<pre class="_prettyXprint">
IMPORTS:
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IRunAndRenderTask;
import org.eclipse.birt.report.engine.api.IGetParameterDefinitionTask;
import org.eclipse.birt.report.engine.api.HTMLRenderOption;
</pre>
<p>Report Generation code:</p>
<pre class="_prettyXprint">
public String getCustomerFacilities() {
String status = "generate customer facilities report";
customerFacilities = "No Facilities Available";
if ( selectedCustomer != null && !selectedCustomer.equals("NONE")) {
try {
Customer customer = customerService.getCustomerByShortname( selectedCustomer);
String internalRef = customer.getInternalRef();
String context = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/");
String reportName = context + CUSTOMER_FACILITIES_REPORT;
log.info("Generate report [" + reportName + "] for customer [" + internalRef + "]");
Connection connection = jdbcTemplate.getDataSource().getConnection();
if ( connection == null || (connection.isClosed()) ) {
throw new Exception("Failed to connect to database");
}
status = "Starting Platform";
EngineConfig engineConfig = new EngineConfig();
Platform.startup( engineConfig );
status = "Create Engine";
IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
IReportEngine engine = factory.createReportEngine( engineConfig );
status = "Create Report Runnable";
IReportRunnable runnable = engine.openReportDesign( reportName );
IRunAndRenderTask task = engine.createRunAndRenderTask( runnable );
IGetParameterDefinitionTask definitionTask = engine.createGetParameterDefinitionTask(runnable);
definitionTask.evaluateDefaults();
status = "Set Parameters";
HashMap<String, Object> params = definitionTask.getDefaultValues();
params.put("p_customer_internal_ref", internalRef);
task.getAppContext().put("OdaJDBCDriverPassInConnection", connection);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFormat("HTML");
options.setOutputStream(bout);
task.setRenderOption(options);
task.setParameterValues(params);
task.run();
customerFacilities = bout.toString();
status = "Shutting down the platform";
connection.close();
task.close();
engine.destroy();
Platform.shutdown();
}
catch ( Exception e ) {
customerFacilities = "Error in generating report, status [" + status + "]";
log.error("ReportBean: failed to generate customer facilities report:\n" + "Status: " + status + "\nReason: " + e.getMessage() );
addErrorMessage("ReportBean","Failed to generate report, see log for details");
}
}
return customerFacilities;
}
</pre>
<p>And displayed using:</p>
<pre class="_prettyXprint">
<a:outputPanel id="customerFacilitiesPanel" >
<r:panel rendered="#{reportBean.renderCustomerFacilitiesReport}" >
<f:facet name="header" >
<h:outputText value="Customer Facilities Report" styleClass="default-header" />
</f:facet>
<h:outputText id="customerFacilitiesReport" value="#{reportBean.customerFacilities}" escape="false" />
</r:panel>
</a:outputPanel>
</pre>
<p>The only useful link I could find to anything that looked like javadoc is:</p>
<pre class="_prettyXprint">
http://grepcode.com/file/repo1.maven.org/maven2/org.eclipse.birt.runtime/org.eclipse.birt.runtime/4.4.1/org/eclipse/birt/report/engine/api/impl/ReportEngine.java?av=f
</pre>
<p>I hope this helps someone else</p>