5

I have stopped an event with preventDefault. Now I want to rethrow it. I tried the fireEvent but that did not work. Is there a way to achieve this?

UPDATE Instead of fire event I created a new instance of the event and used elem.dispatchEvent(clickEvent);

    Event.addNativePreviewHandler(new Event.NativePreviewHandler()
    {
        public void onPreviewNativeEvent(NativePreviewEvent event) 
        {

            if (event.getTypeInt() == Event.ONMOUSEDOWN)
            {
                Element elem = JSHelper.elementFromPoint(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
                EventListener listener = Event.getEventListener(elem);
                if((listener instanceof ListBox))
                {
                    event.getNativeEvent().preventDefault();



                ////    ((ListBox) listener).fireEvent(event);

                    int y = event.getNativeEvent().getClientY();
                    int x = event.getNativeEvent().getClientX();

                    int screenX = event.getNativeEvent().getScreenX();
                    int screenY = event.getNativeEvent().getScreenY();

                    NativeEvent clickEvent = Document.get().createMouseEvent(
                            "click",true, false,0, screenX, screenY, x, y, false, false,
                            false, false, NativeEvent.BUTTON_LEFT, elem);

                    elem.dispatchEvent(clickEvent);



                }
            }
        }
    });
Andrea Boscolo
  • 3,038
  • 1
  • 16
  • 21
Spiff
  • 3,873
  • 4
  • 25
  • 50
  • 1
    I've not used gwt, so I'm unable to offer an answer, but for plain JavaScript (albeit in compliant browsers), MDN has documentation for the [`element.dispatchEvent()`](https://developer.mozilla.org/en-US/docs/DOM/element.dispatchEvent). – David Thomas Aug 29 '12 at 11:23
  • Thanks. I tried it i get: (DISPATCH_REQUEST_ERR): DISPATCH_REQUEST_ERR: DOM Events Exception 1, I googled it : If the Event object is already dispatched in the tree. The browser i'm using is chrome – Spiff Aug 29 '12 at 11:37
  • It looks like that if I create a new instance of the event then i don't get the exception, however it still does not work. – Spiff Aug 29 '12 at 11:52
  • Quick note, I don't believe that preventDefault stops propagation. You must implicitly call event.stopPropagation() to stop the event from propagating. I think the best question is what are you trying to accomplish because I think there may be an easier way to go about it. What are you trying to do with mouse events on the ListBox? Why don't you add a DOM handler to the ListBox? – Chris Hinshaw Aug 30 '12 at 13:55
  • Good question: I'm trying to do make an HTTP call fetch the options, populate the ListBox with the options fetched, and then re-fire the event, and let the ListBox display the options List. – Spiff Aug 30 '12 at 13:59

1 Answers1

-2

Why do u try to fire it again? Just try to call the event handler function you supposed to

Chris'World
  • 9
  • 1
  • 4