2015-11-03 20 views
2

我使用以下代碼創建了BIRT 4.3.0報告。主要的一點是:我想要一個參數foo傳遞到數據集:Birt參數

public File actionPdf() throws EngineException { 
    IReportEngine engine = getEngine(); 

    // Open the report design 
    IReportRunnable design = null; 
    design = engine.openReportDesign("c:\\hello_world.rptdesign"); 

    IRunAndRenderTask task = engine.createRunAndRenderTask(design); 
    task.setParameterValue("foo", "bar"); 
    task.validateParameters(); 

    PDFRenderOption PDF_OPTIONS = new PDFRenderOption(); 
    File f = new File("xyz.pdf"); 
    PDF_OPTIONS.setOutputFileName(f.getAbsolutePath()); 
    PDF_OPTIONS.setOutputFormat("pdf"); 

    task.setRenderOption(PDF_OPTIONS); 

    task.run(); 
    task.close(); 
    return f; 
} 

和數據集如下所示:

public class ActionsPerDateDataSet implements IPojoDataSet { 

public void open(Object obj, Map<String,Object> map) { 
    System.out.println(obj + " map: " + map + " size: " + map.size())  
} 


2015-11-03T13:23:18.993+0100|Information {org.eclipse.datatools.connectivity.oda.util_consumerResourceIds=[email protected]24a1f3df, org.eclipse.birt.data.engine.expression.co[email protected]99fdef1, OdaConsumerId=org.eclipse.datatools.connectivity.oda.profile.connectionPropertyService, PDF_REN[email protected]491c843} map: {} size: 0 

但沒有參數我foo set.How可以得到它?

+0

是否定義在報告中指出的參數?我現在不活躍地使用birt,所以我回答了我的想法。我記得,一個數據集沒有參數。報告可以有參數,您可以在數據集中使用這些參數。 –

+0

hm ...我的計劃是使用open方法中的參數從數據庫加載數據。這通常是正確的方法嗎? – matthias

+0

我記得我做了很多參數。更改數據源,創建查詢等。查看報告的生命週期,有幾個地方可以讓ECMA Script在生成時處理報告。所以你的想法是正確的,因爲我的理解是正確的。 –

回答

2

從外部,您將參數傳遞給報告而不是數據集。 您必須區分報告參數和數據集參數。 在報告中,數據集參數可以從從報告參數中獲取其值,但這不是自動的。數據集參數也可以從佈局上下文中獲取其值(請參閱屬性中的數據集參數綁定按鈕)。

有關詳細信息,請參閱BIRT文檔。

如果您是來自其他報告設計工具,您可能會發現這種繁瑣且過於複雜,但實際上它是一個很棒的功能,因爲這允許在報告中多次重複使用相同的數據集,並且是重用組件的基礎通過引用他們從圖書館。

1

您需要在報告設計中定義參數。

Creation of the parameter called masterbomid in your case it would be named as foo.

Assignment into a dataset used for the report it will take the value you send on the task.setParameterValue("foo", "bar");