tags:

views:

21

answers:

1

Hi

I have a report that will require chunks of text (that will be created dynamically) to be embedded from a Java program that runs the report.

Is there a way I can put a text object into the design and then somehow get hold that of that object in my Java program. If this is possible I assume I would be able to insert text into that text object.

Is this the best way to do this? A code snippet would be gratefully accepted.

Thanks in advance.

+1  A: 

You can easily do this by using Java Event Handlers. Any event in the generation process can be modified either by JavaScript (stored on the report design itself) or via a POJO when more complex processing is needed.

Add a TextItem to your report. This will be the intended destination for your block of text. You can add other types of controls and interact with them the same way, TextItem just seems to make sense for this particular question. Add anything you want to the text item, we are going to over-ride the value from the POJO anyway.

Now create a POJO that implements the TextItemEventAdapter interface (this should be in your BIRT distribution). You can then choose what event to bind your POJO to. onCreate probably makes the most sense. To do that, implement the onCreate method from the interface.

/* (non-Javadoc)
 * @see org.eclipse.birt.report.engine.api.script.eventadapter.TextItemEventAdapter#onCreate(org.eclipse.birt.report.engine.api.script.instance.ITextItemInstance, org.eclipse.birt.report.engine.api.script.IReportContext)
 */
@Override
public void onCreate(ITextItemInstance text, IReportContext reportContext) {
    super.onCreate(text, reportContext);
    text.setText(getText());
}

In the above snippet, the getText() method is another method on your class that builds your text block. Implement your business logic here.

Once you have built the class, you need to bind it to the report's text item control. On the report, select the text item. Under "Properties" look for "Event Handler". Here you can add your POJO as the event handler for the control. When the control is rendered, your POJO will now supply the text.

To ease development, have your Java Project and your BIRT project in the same workspace. This will allow the report and the POJO to see each other enabling testing and debugging inside Eclipse.

Here is a lot more background about report events and event handling: http://www.eclipse.org/birt/phoenix/deploy/reportScripting.php

Good Luck!

MystikSpiral