Event onCreate is called after Event onRender [message #1690107] |
Wed, 25 March 2015 06:07  |
Eclipse User |
|
|
|
I have designed an Report with a Grid and a Table.
I put the Value of a DataItem in the Table to a Variable by:
onCreate (Script executed when the element is created in the Factory)
reportContext.setPersistentGlobalVariable("total",this.getValue().toString);
I read now the Value of the Variable "total" in a DataItem in the Grid by:
onRender (Script executed when the element is prepared for rendering in the Presentation engine)
tmp = "";
tmp = reportContext.getPersistentGlobalVariable("total");
this.setDisplayValue(tmp);
When I log the events, than the event onCreate comes after onRender
This is for me very strange. It must be a Bug.
Question: How can I read the value by this way and use it then?
Attached i send you the report-File
I use Birt 4.1 and den DemoDataBase of Birt.
|
|
|
|
Re: Event onCreate is called after Event onRender [message #1690211 is a reply to message #1690107] |
Wed, 25 March 2015 13:02   |
Eclipse User |
|
|
|
If you use the RunAndRender task (from the designer, this is any run option besides the web viewer) the each item is rendered as it's created, which with your scripting, would give you the sense that the onRender ran first. However, if you put logging script into the onRender of the data element in the table footer, you'd see that one show up after the onCreate.
Try it with the web viewer. If you're wanting PDF, change the __format url parameter value to pdf after you run it to the web viewer. This will give you the tasks separately and you'll see the logging happen properly.
For your example to work, remove this line from your initialize script:
reportContext.setPersistentGlobalVariable("total", "0");
The initialize method runs before the run task and before the render task, so your PGV is reset to 0 before you onRender scripts run.
Hope this helps.
|
|
|
Re: Event onCreate is called after Event onRender [message #1690263 is a reply to message #1690211] |
Thu, 26 March 2015 04:28  |
Eclipse User |
|
|
|
Have a lot to thanks for your reply.
It works now.
I use the report with java and i have seperated in java the run-Task and render-Task.
With the following javacode it is working:
public class PrintReport {
private final static String LOG_DIR = "./birt/logs/";
private final static String OUTPUT_DIR = "./birt/outputs/";
private final static String REPORT = "./birt/reports/Report06.rptdesign";
private final static String BINARY_REPORT = "./birt/reports/Binary_Report06.rptdesign";
public static void main(String[] args) {
PrintReport printReport = new PrintReport();
try {
printReport.generateReport();
} catch (BirtException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void generateReport() throws BirtException {
IReportEngine reportEngine = null;
IReportRunnable reportRunnable = null;
IReportDocument reportDocument = null;
IRunTask runTask = null;
IRenderTask renderTask = null;
EngineConfig engineConfig = new EngineConfig();
IPlatformContext context = new PlatformFileContext();
engineConfig.setLogConfig(LOG_DIR, Level.FINE);
engineConfig.setEngineContext(context);
try {
// start the eclipse Platform
Platform.startup(engineConfig);
// get ReportEngine
IReportEngineFactory reportEngineFactory = (IReportEngineFactory) Platform
.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
reportEngine = reportEngineFactory.createReportEngine(engineConfig);
// create new Instance of report Report06.rptdesing
reportRunnable = reportEngine.openReportDesign(REPORT);
// Generate the Report
runTask = reportEngine.createRunTask(reportRunnable);
runTask.run(BINARY_REPORT);
// Binary ReportDocument
reportDocument = reportEngine.openReportDocument(BINARY_REPORT);
// Render the Report
renderTask = reportEngine.createRenderTask(reportDocument);
// Create Output-File
ByteArrayOutputStream fso = new ByteArrayOutputStream();
PDFRenderOption options = new PDFRenderOption();
options.setOutputStream(fso);
options.setOutputFileName(OUTPUT_DIR + "File.pdf");
options.setOutputFormat(PDFRenderOption.OUTPUT_FORMAT_PDF);
options.setEmitterID(PDFRenderOption.OUTPUT_EMITTERID_PDF);
options.setSupportedImageFormats("PNG");
// render the report
renderTask.setRenderOption(options);
renderTask.setPageNumber(1);
renderTask.render();
// Finished
renderTask.close();
reportDocument.close();
runTask.close();
reportEngine.shutdown();
Platform.shutdown();
System.out.println("Finished");
} catch (BirtException e) {
e.printStackTrace();
reportEngine.destroy();
}
}
}
But i have now another question, but this is not so important:
When I add the following java-code to get the TOC, nothing happens
// BinaryReportDocument
reportDocument = reportEngine.openReportDocument(BINARY_REPORT);
// Special: list TableOfContents of report
TOCNode tableOfContentsNode = reportDocument.findTOC(null);
java.util.List children = tableOfContentsNode.getChildren();
if (children != null && children.size() > 0) {
for (int i = 0; i < children.size(); i++) {
TOCNode child = (TOCNode) children.get(i);
System.out.println("Node ID " + child.getNodeID());
System.out.println("Node Display String "
+ child.getDisplayString());
System.out.println("Node Bookmark " + child.getBookmark());
}
}
// Render the Report
renderTask = reportEngine.createRenderTask(reportDocument);
The if-Statement in this Code is never "true".
What must i do to get the TOC in this example?
But this question is not so important. We will not spend to much time for it.
You have helped me in former times so much in important questions for which i want to say here one time "Thank you".
|
|
|
Powered by
FUDForum. Page generated in 0.04931 seconds