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

江枫思渺然 提交于 2019-12-04 19:34:16


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.

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!


    public class ReportGenerator {
        public static void main(String args[]) throws Exception{
        ReportGenerator rg = new ReportGenerator();

        @SuppressWarnings({ "unchecked", "deprecation" })
        public void executeReport(String activeIndicator) throws EngineException {

        IReportEngine engine=null;
        EngineConfig config = null;

            config = new EngineConfig( );            
            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);
            HashMap<String, String> params = parameterDefinitionTask.getDefaultValues();
            params.put("aIndicator", activeIndicator);

            ConnectionHelper connectionHelper = new ConnectionHelper();
            task.getAppContext().put("OdaJDBCDriverPassInConnection", connectionHelper.getConnection());

            PDFRenderOption options = new PDFRenderOption();


        } catch (Exception ex) {
        } finally {


You need to set the parameters on the IRunAndRenderTask:

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