Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Event onCreate is called after Event onRender
Event onCreate is called after Event onRender [message #1690107] Wed, 25 March 2015 10:07 Go to next message
Hans-Georg Glöckler is currently offline Hans-Georg GlöcklerFriend
Messages: 88
Registered: July 2009
Member
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 #1690205 is a reply to message #1690107] Wed, 25 March 2015 16:41 Go to previous messageGo to next message
Jesse Freeman is currently offline Jesse FreemanFriend
Messages: 184
Registered: January 2015
Senior Member
When I run the sample report you attached, both the onRender events are happening after the onCreate event.

I've attached the log file generated in my environment.

Can you attach the log file from when you are running the report in your environment?
  • Attachment: birt.log
    (Size: 1.39KB, Downloaded 268 times)
Re: Event onCreate is called after Event onRender [message #1690211 is a reply to message #1690107] Wed, 25 March 2015 17:02 Go to previous messageGo to next message
Michael Williams is currently offline Michael WilliamsFriend
Messages: 1925
Registered: July 2009
Senior Member

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.


Michael

Developer Evangelist, Silanis
Re: Event onCreate is called after Event onRender [message #1690263 is a reply to message #1690211] Thu, 26 March 2015 08:28 Go to previous message
Hans-Georg Glöckler is currently offline Hans-Georg GlöcklerFriend
Messages: 88
Registered: July 2009
Member
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".
Previous Topic:Hide icons in footer based on PageNumber
Next Topic:working examples pie chart, line chart
Goto Forum:
  


Current Time: Sun Jul 21 11:18:36 GMT 2024

Powered by FUDForum. Page generated in 0.03487 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top