Monday, May 18, 2009

BIRT: Accessing the Report Context in Java Chart Event Handler

After Googling this, it seems that this is a common question that has no posted answers. seriously, thats annoying. I hate when that happens.

Anyway, so what I needed was to set a property in the report context that could be accessed withing a chart event. Now, if I was using the Javascript handler, something like the following would be sufficient:
context.getExternalContext().getScriptable()

However, this does not return anything close to a context in a Java event handler. The
context.getExternalContext() returns a BIRTExternalContext object, this is not a public accessible class. And getScriptable
returns a NativeJavaObject. So, in a way that is not documented anywhere, you can do the
following to get access to an IReportContext object from within a Java Event handler for charts:

Object o = icsc.getExternalContext().getObject();
IReportContext context = (IReportContext)o;

Thats it. Not sure why this is not documented anywhere since it seems to be asked a bunch.

1 comment:

jutta said...

This was exactly what I was looking for. Thanks!