{"id":10310,"date":"2012-09-21T11:37:29","date_gmt":"2012-09-21T10:37:29","guid":{"rendered":"http:\/\/touk.pl\/blog\/?p=10310"},"modified":"2023-03-22T16:03:31","modified_gmt":"2023-03-22T15:03:31","slug":"easy-firing-click-event-from-code-in-gwt","status":"publish","type":"post","link":"https:\/\/touk.pl\/blog\/2012\/09\/21\/easy-firing-click-event-from-code-in-gwt\/","title":{"rendered":"Easy firing click event from code in GWT"},"content":{"rendered":"<p>Firing native events in GWT can be a real pain. If you need to fire a click event when the user press ENTER (or any other key that you want to work like CLICK) on any custom-made element, theoretically you should use:<\/p>\n<p>*DomEvent.fireNativeEvent(com.google.gwt.dom.client.NativeEvent, com.google.gwt.event.shared.HasHandlers) * Minimal code (without required parameters) linked with this approach: <code>NativeEvent event = Document.get().createChangeEvent();<br \/>\nDomEvent.fireNativeEvent(event, this);<\/code> <code>public final NativeEvent createClickEvent(int detail, int screenX, int screenY, int clientX, int clientY, boolean ctrlKey, boolean altKey, boolean shiftKey, boolean metaKey)<\/code> This is the place where native JSNI approach is much more clearer: <code>public static native void click(Element element)\/*-{<br \/>\nelement.click();<br \/>\n}-*\/;<\/code><\/p>\n<p>This approach is very useful for custom made buttons that for some reason can not extend basic Button class. In any other case try not to simulate &#8220;user actions&#8221; in your handlers. Launch designated business methods instead.<\/p>\n","protected":false},"excerpt":{"rendered":"Firing native events in GWT can be a real pain. If you need to fire a click event&hellip;\n","protected":false},"author":18,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[385,386,71,28,68,388],"class_list":{"0":"post-10310","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-development-design","7":"tag-click-event","8":"tag-custom-widget","9":"tag-frontend","10":"tag-gwt","11":"tag-java","12":"tag-jsni"},"_links":{"self":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/10310","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/comments?post=10310"}],"version-history":[{"count":12,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/10310\/revisions"}],"predecessor-version":[{"id":15531,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/10310\/revisions\/15531"}],"wp:attachment":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/media?parent=10310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/categories?post=10310"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/tags?post=10310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}