如何设置BIRT报告设计器通过BIRT API创建的BIRT报告并将参数传递给BIRT报告? [英] How do you set and pass a parameter to a BIRT report created by the BIRT Report Designer through the BIRT API?

查看:141
本文介绍了如何设置BIRT报告设计器通过BIRT API创建的BIRT报告并将参数传递给BIRT报告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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. 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. I pass all my parameters in through 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. 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. 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

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

If you go to the link go down to #4 and see the list of tasks to do. 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

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


推荐答案

您需要在IRunAndRenderTask设置参数:

You need to set the parameters on the IRunAndRenderTask:

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

这篇关于如何设置BIRT报告设计器通过BIRT API创建的BIRT报告并将参数传递给BIRT报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆