如何设置BIRT报告设计器通过BIRT API创建的BIRT报告并将参数传递给BIRT报告?

我创建了一个简单的报告,它只需要一个参数。 此参数在查询中使用,并在报表设计器中直接执行时执行。 顺便说一句,我没有使用javascript或任何脚本编写此报告。 我看到有些人试图在这里使用脚本和/或javascripts来传递参数,但这不是我正在做的事情。 我通过java传递所有参数。 继续,在本报告中,我列出了活动/非活动项目。 我传入一个’N’表示非活动项目,一个’Y’表示活动项目。 当我尝试通过API传递一个参数时,无论我传入什么内容,我总是得到一个活动项列表。顺便说一句,“Y”是传入的参数的默认值。(我将覆盖默认值)下面的代码)我遇到的问题是报告似乎不想采取我设置的参数。 是的,传入的变量中的值更改但报告未反映更改。 我的代码如下。 我试图遵循此链接的建议以及如何设置参数。

http://www.eclipsezone.com/eclipse/forums/t67723.html

如果你转到链接,请转到#4并查看要执行的任务列表。 这是我试图遵循的。 我觉得我可能会遗漏一些东西。 如果你有这个问题,你可以给我一些我缺少的建议吗? 非常感谢!

-Dale

public class ReportGenerator { public static void main(String args[]) throws Exception{ ReportGenerator rg = new ReportGenerator(); rg.executeReport("N"); } @SuppressWarnings({ "unchecked", "deprecation" }) public void executeReport(String activeIndicator) throws EngineException { IReportEngine engine=null; EngineConfig config = null; try{ config = new EngineConfig( ); config.setBIRTHome("C:\\birt-rcp-report-designer-3_7_2\\ReportEngine"); config.setLogConfig("c:/temp/test", Level.FINEST); Platform.startup( config ); IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY ); engine = factory.createReportEngine( config ); IReportRunnable reportDesign = null; reportDesign = engine.openReportDesign("C:\\workspace\\SimpleReport\\ReportTemplates\\ItemListingReport.rptdesign"); IRunAndRenderTask task = engine.createRunAndRenderTask(reportDesign); IGetParameterDefinitionTask parameterDefinitionTask = engine.createGetParameterDefinitionTask(reportDesign); parameterDefinitionTask.evaluateDefaults(); HashMap params = parameterDefinitionTask.getDefaultValues(); params.put("aIndicator", activeIndicator); parameterDefinitionTask.setParameterValues(params); ConnectionHelper connectionHelper = new ConnectionHelper(); task.getAppContext().put("OdaJDBCDriverPassInConnection", connectionHelper.getConnection()); PDFRenderOption options = new PDFRenderOption(); options.setOutputFormat("pdf"); options.setOutputFileName("C:\\workspace\\SimpleReport\\output\\itemListingReport.pdf"); task.setRenderOption(options); task.run(); task.close(); engine.destroy(); } catch (Exception ex) { ex.printStackTrace(); } finally { Platform.shutdown(); } } } 

您需要在IRunAndRenderTask上设置参数:

 IRunAndRenderTask task = engine.createRunAndRenderTask(reportRunnable); Map< String, Object > birtParams = ...; task.setParameterValues( birtParams );