开发者

Why should I use BIRT setGlobalVariable() method?

开发者 https://www.devze.com 2023-02-19 06:42 出处:网络
I\'ve some reports where I use JavaScript variables between different event handlers. Example: //D开发者_JAVA百科ata Set beforeOpen:

I've some reports where I use JavaScript variables between different event handlers.

Example:

//D开发者_JAVA百科ata Set beforeOpen:
fooList = "";

//Data Set fetch:
fooList += row['foos'] + ", ";

//Dynamic Text expression, somewhere in the report:
fooList

This code works for me in 2.6.2. (There is an invisible table above this DynamicText which triggers Data Set use)

Documentation says, that I should use reportContext.setGlobalVariable("foo","bar");, but I haven't yet found, that using simple assignments is discouraged.

What are disadvantages of using simple assignments in BIRT Javascript event handlers, such as foo="bar"; and reading it later in another event handler?


By setting your variables this way you are in fact able to access them anywhere in the scripting layer. If you need to extend the reach of the variable into compiled code via a Java event handler, you would need to use the global variable to use the variable.

There is no added cost to this approach and making it a best practice ensures if you do cross any boundaries the variable's state is maintained and available for you anywhere you may need it.

Good Luck!

0

精彩评论

暂无评论...
验证码 换一张
取 消