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 10:09 Go to next message
Jan Krakora is currently offline Jan KrakoraFriend
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 13:51 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
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 20:33 Go to previous messageGo to next message
Michael Williams is currently offline Michael WilliamsFriend
Messages: 1925
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?
Re: More instance of IImageEventHandler [message #1075849 is a reply to message #1075653] Tue, 30 July 2013 07:37 Go to previous message
Jan Krakora is currently offline Jan KrakoraFriend
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 Dec 09 06:05:19 GMT 2016

Powered by FUDForum. Page generated in 0.20353 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software