简体   繁体   English

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

[英]How do you set and pass a parameter to a BIRT report created by the BIRT Report Designer through the BIRT API?

I've created a simple report that takes a single parameter. 我创建了一个简单的报告,它只需要一个参数。 This parameter is used in the query and executes fine when directly executed in the report designer. 此参数在查询中使用,并在报表设计器中直接执行时执行。 By the way I'm not using javascript or any scripting for this report. 顺便说一句,我没有使用javascript或任何脚本编写此报告。 I've seen some people trying to pass parameters using scripts and/or javascripts for answers here, however this is not what I'm doing. 我看到有些人试图在这里使用脚本和/或javascripts来传递参数,但这不是我正在做的事情。 I pass all my parameters in through java. 我通过java传递所有参数。 Continuing, in this report I'm listing active/inactive items. 继续,在本报告中,我列出了活动/非活动项目。 I pass in an 'N' for listing inactive items and a 'Y' for active items. 我传入一个'N'表示非活动项目,一个'Y'表示活动项目。 When I try to pass in a parameter through the API, I always get a list of active items regardless to what I pass in. By the way 'Y' is the default value of the parameter passed in. (I am overriding the defaults in the code below) The problem I'm having is that the report doesn't seem to want to take the parameter I set. 当我尝试通过API传递一个参数时,无论我传入什么内容,我总是会得到一个活动项列表。顺便说一下,'Y'是传入参数的默认值。(我将覆盖默认值)下面的代码)我遇到的问题是报告似乎不想采取我设置的参数。 Yes the value changes in my variable passed in but the report doesn't reflect the change. 是的,传入的变量中的值发生了变化,但报告未反映更改。 My code is below. 我的代码如下。 I've tried to follow the advice of this link and how to set the parameters. 我试图遵循此链接的建议以及如何设置参数。

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

If you go to the link go down to #4 and see the list of tasks to do. 如果你转到链接,请转到#4并查看要执行的任务列表。 This is what I have tried to follow. 这是我试图遵循的。 I feel I may be missing something. 我觉得我可能会遗漏一些东西。 If you've got this going could you give me some advice to what I'm missing? 如果你有这个问题,你可以给我一些我缺少的建议吗? Thanks much! 非常感谢!

-Dale -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<String, String> 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();
        }
        }
    }

You need to set the parameters on the IRunAndRenderTask: 您需要在IRunAndRenderTask上设置参数:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM