1

I am trying to simulate a mouse click event on GWT (Google Web Toolkit) Application in <=IE8 (using fireEvent, not dispatchEvent)

A sample custom button can be found here: http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwCustomButton (The toggle button is easiest to see if the click was processed)

The major boilerplate for simulating the click can be found here: https://stackoverflow.com/a/6158050 (This is where I got the simulate function used below)

I have been able to successfully simulate the click event by using the following commands for IE9+ (in this case simulate used dispatchEvent)

simulate(document.getElementById("gwt-debug-cwCustomButton-toggle-normal"), "mouseover");
simulate(document.getElementById("gwt-debug-cwCustomButton-toggle-normal"), "mousedown");
simulate(document.getElementById("gwt-debug-cwCustomButton-toggle-normal"), "mouseup");

In my application the fireEvent fails, because GWT's $wnd.event is null. (Line: 117, https://github.com/stephenh/google-web-toolkit/blob/master/user/src/com/google/gwt/user/client/impl/DOMImplTrident.java)

If there is no way to simulate the click with plain JS, then is there a way to use GWT's EventDispatcher to simulate the click?

Edit: I have not access to GWT environment

PrivatMamtora
  • 2,072
  • 2
  • 19
  • 29
  • Possible duplicate of [Firing click event from code in gwt](http://stackoverflow.com/questions/1238355/firing-click-event-from-code-in-gwt) – walen Jan 27 '17 at 11:32
  • Actually that is ask how to fire it in the GWT Java code, I am asking how to do it on the front-end in JavaScript – PrivatMamtora Jan 27 '17 at 20:10
  • Sorry, I might have misunderstood when you said `$wnd.event` was null (`$wnd` is normally used in JSNI Java methods) and later when you asked how to do it with GWT's `EventDispacher` Java class. So, for some reason, you need to do it with JS... Have you tried jQuery? `$("gwt-debug-cwCustomButton-toggle-normal").click()` should work reasonably well unless you want to also simulate the `onMouseOver` visual effect. – walen Jan 28 '17 at 09:53
  • one certain way is to write the GWT java code, then expose that java method as a JSNI method. After all the GWT java code *is* front-end code. – geert3 Jan 31 '17 at 15:56
  • @walen In IE8, event.target doesn't work as expected, so what GWT does is to keep track of all events fired, I guess using the custom attribute `__eventBits`, so to 'stimulate' a click things need to happen in a certain sequence. – PrivatMamtora May 26 '17 at 14:08
  • @geert3 Yes, I did look into it, but I don't have access to application. – PrivatMamtora May 26 '17 at 14:11
  • @walen not works; https://web.awbeditor.com/WebQuickTry `$('.GD3K2OHCJN').click();$('.gwt-PushButton:eq(2)').click()` – Smart Manoj Nov 11 '19 at 11:37

0 Answers0