2015-11-03 64 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");