Hi
Create a class which generates dynamic name on each call.
public class JSNIHelper {
private static int requestCounter = 0;
public static
String registerCallbackFunction(MyClass obj) {
String dynamicName = "jsni" + (requestCounter++);
// you can write your own logic to generate dynamic name for
createDynamicFunction(obj, dynamicName);
return callbackName;
}
private native static void createDynamicFunction(MyClass obj, String dynamicName )/*-{
tmp = function( name ){
obj.@example.myclass::execute(Ljava/lang/String;)( name );
};
$wnd[dynamicName]=tmp;
}-*/;
}
// Your Class where you will call
// Pass object of 'MyClass'
public void onClick(ClickEvent event) {
String callbackName = JSNIHelper.registerCallbackFunction(new MyClass() {
});
// do other things
}
Hope it will help....