Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » More instance of IImageEventHandler
More instance of IImageEventHandler [message #1073690] Thu, 25 July 2013 06:09 Go to next message
Jan Krakora is currently offline Jan Krakora
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
I have an image element within my report with an element handler where I do some logic in its onPrepare and onCreate methods.

When I generate the report using 'runAndRender' task, the handler instance is created only once. But when I just run the 'run' task, the handler is instantiated once for each method - so there are two instances.

Is this expected behavior? My handler is stateful, so it breaks my report.

I have set 'New handler on each event' to false. My Birt version is 3.7.2.
Re: More instance of IImageEventHandler [message #1073795 is a reply to message #1073690] Thu, 25 July 2013 09:51 Go to previous messageGo to next message
Jan Krakora is currently offline Jan Krakora
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
I can see this behavior also when running 'runAndRender' task. So it's a problem of a concrete report.
Other reports (also with image and that handler), creates only one instance.

What am I missing here??
Re: More instance of IImageEventHandler [message #1075653 is a reply to message #1073795] Mon, 29 July 2013 16:33 Go to previous messageGo to next message
Michael Williams is currently offline Michael Williams
Messages: 1547
Registered: July 2009
Senior Member

In the other reports where you only see one instance, do you use the handler in both script methods? Or just one?

Michael

Add interactivity, scheduling, sharing, live Excel export, and JS integration to your BIRT app with the new, free BIRT server, BIRT iHub F-Type.
Re: More instance of IImageEventHandler [message #1075849 is a reply to message #1075653] Tue, 30 July 2013 03:37 Go to previous message
Jan Krakora is currently offline Jan Krakora
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
I use the same handler in all reports:
public class SplmageEventHandler extends ImageEventAdapter {

	private String columnName;
	
	@Override
	public void onPrepare(IImage imageHandle, IReportContext reportContext) throws ScriptException {
		columnName = StringUtils.substringBetween(StringUtils.substringBetween(imageHandle.getValueExpression(), "[", "]"), "\"", "\"");
	}
	
	@Override
	public void onCreate(IImageInstance image, IReportContext reportContext) throws ScriptException {
		final Object data = image.getRowData().getColumnValue(getColumnName());
		if (data != null) {
			...
			if (...) {
				image.setMimeType("image/svg+xml");
			}
		}
	}

	public String getColumnName() {
		return columnName;
	}

}

Basically it sets mime type based on the passed data type. I just need onPrepare to get column binding name (the handler is general and is used for every dynamic image in my reports).
Previous Topic:Populate report parameter based on another parameters selection
Next Topic:change date parameter value from script
Goto Forum:
  


Current Time: Fri Aug 01 03:56:16 EDT 2014

Powered by FUDForum. Page generated in 0.02249 seconds