How to simulate a click for a GWT button using fireEvent

1,015 views
Skip to first unread message

Privat

unread,
Jan 27, 2017, 4:42:19 AM1/27/17
to GWT Users

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: http://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?

natan clara

unread,
Jan 27, 2017, 12:49:06 PM1/27/17
to google-we...@googlegroups.com

I have use this.

this.getComo().addKeyPressHandler(new KeyPressHandler() {
            @Override
            public void onKeyPress(KeyPressEvent event) {
                int teclado = event.getNativeEvent().getKeyCode();
                if ((teclado == KeyCodes.KEY_ENTER)) {
                    getEntrar().fireEvent(new GwtEvent<ClickHandler>() {
                        @Override
                        protected void dispatch(ClickHandler handler) {
                            handler.onClick(null);
                        }

                        @Override
                        public com.google.gwt.event.shared.GwtEvent.Type<ClickHandler> getAssociatedType() {
                            return ClickEvent.getType();
                        }
                    });

                }
            }
        });

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Privat

unread,
Jan 27, 2017, 3:22:15 PM1/27/17
to GWT Users
Hello Nantanael,

You have provided GWT Java code. You might have misunderstood.
I wish to fire the event in JavaScript, on the front-end. (The compiled code)

I have no access to the GWT code. I simply want to manipulate the front end (The compiled code)

What I am asking requires knowledge of how the GWT event bus operates in IE8.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages