Believe it or not, but your JS example is doing too much work. Unless
you're porting existing code, in which case you're actually just writing
wrappers, there should be a good reason to write a JSNI routine that's
more than one or two lines. This example does not clear that bar.
OTOH, maybe you should be using the GWT event bus. From an architectural
perspective, I think that's a better choice. Instead of using
window.dispatch(), fire the event via a JSNI method. So, your first JS
sample should become a JSNI routine that calls a Java routine that calls
eventBus.fire(), and your second example should become Java. It's
possible to call eventBus.fire() entirely within JSNI, but getting that
eventBus argument to your JSNI method may be problematic.
Interesting problem.
Are you sure the event data is kept for the case of js --> js?
I'd eliminate that possibility first. I'm sure it works, but nothing
you've said so far positively eliminates that (admittedly small)
possibility.
If it /is/ kept, then:
0) write an event hander in js (i.e. outside gwt) that calls
addLookupResultHandler
1) load the event handler from step 0 as part of your external library's
load phase
2) hook your addLookupResultHandler to GWT's $wnd object before step 3)
3) fire the event in the library. That will call the event handler
written in step 0
OK
> I'll try your suggestion for alternative way of handling the event
Just to be clear, the event handler from step 0 calls the
addLookupResultHandler via GWT's $wnd object. I think you know that, but
I missed that point in the previous post.