Using Javascript reportContext.setPersistentGlobalVariable method on Birt handlers To pass objects between processes

两盒软妹~` 提交于 2019-12-13 02:47:24

问题


I trying to pass variable from the factory process to the run process , using reportContext.setPersistentGlobalVariable in the eclipsde UI perspective. In the onFetch() of the data set the code look like this:

var flag = "hello";
reportContext.setPersistentGlobalVariable("flag", flag);

In the beforeRender() method of the report design the code look like this:

var flg = reportContext.getPersistentGlobalVariable("flag");
reportContext.getDesignHandle().findElement("text").setContent(flg);

It should be noted that this code is works when I put the two snippets in two of the report design on..() methods. Somehow the data not pass between the two processes.


回答1:


I was able to reproduce a behavior similar to what you describe. Please try to insert a Dynamic text element at the end of the report and set this expression, it should work:

reportContext.getPersistentGlobalVariable("flag");

Most likely your reports are running with a unique "RunAndRender" task, whereas if we want to take advantage of beforeRender & onRender events we should use two separate "Run" and "Render" task.

In practice with Eclipse Designer, if we run reports using the Web Viewer ("View report in Web Viewer") there are two separate tasks but if we directly run an export ("View report as xxx") there is a single task.

That said, it is important to notice handling render events is tricky: most of the time it is too late to change designHandle elements as you try to do here. Even the "visibility" property of elements can't be changed at render time, for example. You can change the content of a text using "onRender" event of this element though:

this.text=reportContext.getPersistentGlobalVariable("flag");


来源:https://stackoverflow.com/questions/28959510/using-javascript-reportcontext-setpersistentglobalvariable-method-on-birt-handle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!