Integrating and Extending BIRT: Using Scripting in a Report Design
BIRT provides a powerful scripting capability that enables a report developer to create custom code to control various aspects of report creation. This chapter provides an overview of scripting in BIRT. Subsequent chapters focus on implementing script event handlers in JavaScript and Java, writing event handlers for charts, and accessing data using scripted data sources.
Overview of BIRT scripting
BIRT Report Designer supports writing custom event handlers in both Java and JavaScript. BIRT RCP Report Designer supports writing custom event handlers only in JavaScript.
Choosing between JavaScript and Java
Both JavaScript and Java have advantages and disadvantages when writing an event handler. For a developer who is familiar with only one of the two languages, the advantage of using the familiar language is obvious, but for others the decision depends on the report requirements.
The advantages of using JavaScript to write an event handler include:
-
Ease of adding a simple script for a particular event handler Adding a JavaScript event handler to a report is less complicated than adding an event handler written in Java. To write a JavaScript event handler, there is no need to create a Java environment in Eclipse or to learn the Eclipse Java development process. There is no requirement to specify a package, implement an interface, or know the parameters of the event handler you write.
To add a JavaScript event handler, first select the name of the event handler from a drop-down list on the Script tab. Then, type the code.
- Simpler language constructs, looser typing, and less strict language rules JavaScript is less demanding to code than Java due to its more relaxed requirements.
The advantages of using Java to write an event handler include:
-
Availability of the Eclipse Java development environment
The Eclipse Java development environment is very powerful and includes such features as autocompletion, context sensitive help, keyboard shortcuts, and parameter hints.
-
Ease of finding and viewing event handlers
All the Java event handlers for a report exist in readily viewable Java files. By contrast, the JavaScript event handlers are embedded in the design and you can view only one handler at a time.
Using both JavaScript and Java
There is no requirement to write all event handlers in one language. You can write some in JavaScript and others in Java. If both a JavaScript and a Java event handler for the same event are available, BIRT uses the JavaScript handler.