The issue is that the JS function is written by some other library.
The custom event will be fired not by my module but by other code on
the page . I however need to listen to that event, and get the
customData out of that event for further processing within the
module.
I have tried to use DOM.sinkBitlessEvent (and seeing if I can catch
this event in onBrowserEvent() ), but that didn't work. Not sure what
other way I can get that event , or why does the custom event looses
its customData when within JSNI method


On Aug 11, 8:17 am, Jeffrey Chimene <[email protected]> wrote:
> On 8/10/2011 4:50 PM, e-lena-s wrote:
>
>
>
>
>
>
>
> > I am trying to listen to a custom JS event that is created outside my
> > GWT module. In my JS file I create the event, and then fire it as
> > such :
>
> >         var evt = document.createEvent("Event");
> >    evt.initEvent('customEvent', true, true);
> >    evt.customData = "someData";
>
> >    window.addEventListener('customEvent', function(evt)
> > { console.log("test: " + evt.customData)}, false);
> >    window.dispatchEvent(evt);
>
> > Now, in my GWT code, I have a JSNI method that adds a listener  to
> > listen to my customEvent  and act on it. Code as follows:
>
> > public native void addLookupResultHandler()/*-{
> >          $wnd.addEventListener('lookupEntitySelected',
> > $entry(function(evt){
>
> > console.log("gwt: " + evt.customData);
>
> > console.log("gwt: " + evt.type);
>
> > @myClassName::handleEvent(LmyCustomEventEvent;)(evt)
> >                                                         }), false);
> >      }-*/;
>
> > The problem I have is that the customData is being dropped when the
> > event gets to JSNI code. I can see that the event listner written in
> > JS does get the correct event with the correct customData, but logging
> > the event properties in JSNI shows that customData is undefined (event
> > type looks correct though)
>
> > Am I doing something wrong here ?
>
> > Is there may be a better way to create custom events (it has to be
> > created in JavaScript, since the code firing it won't be in GWT
> > module)
>
> My earlier answer was not correct. I don't see why
> addLookupResultHandler is a JSNI routine. I think you want to write it
> in GWT, via handling a NativeEvent. However, I've never tried this, so
> it may not work as you intend.
>
> 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.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to