2012-05-25 38 views
9

我已經創建了一個簡單的報告,它只接受一個參數。該參數在查詢中使用,在報表設計器中直接執行時可以正常執行。順便說一句,我沒有使用JavaScript或任何腳本的這個報告。我看到一些人試圖通過腳本和/或javascripts來傳遞參數來獲得答案,但這不是我正在做的。我通過java傳遞所有參數。繼續,在本報告中,我列出了有效/無效項目。我通過'N'列出非活動項目和'Y'活動項目。當我嘗試通過API傳遞一個參數時,無論我傳入什麼,我都會得到一個活動項目列表。順便說一下,'Y'是傳入的參數的默認值。(我重寫了默認值下面的代碼)我遇到的問題是報告似乎不想採用我設置的參數。是的,我的變量中的值發生了變化,但報告沒有反映出變化。我的代碼如下。我試圖按照此鏈接的建議以及如何設置參數。如何設置參數並將其傳遞給由BIRT報表設計器通過BIRT API創建的BIRT報表?

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

回答

11

您需要設置在IRunAndRenderTask參數:

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

在以前的版本(BIRT 4前),所有我需要做的就是新EngineConfig()。 setAppContext(birtParams)。 –