I would like to call a method of a GWT object (to open a GWT popup, to refresh the screen or to send an event to the GWT object). And I would like to know how can I get the instance of the GWT object into my JavaScript code.
I use GWT 2.8 with JSInterop. I know how to create a new instance, but I would like to get an instance which is already created.
DOM Element -> GWT Widget, onlyGWT Widget -> DOM ElementandGWT Widget -> GWT Widget.Also doesn't have opportunity direct creating GWT Widget in javascript code. If you want it, you must create a wrapper class with JsInterop API. Example:
Using this class in javascript:
Сonsidering item 1, you must get from Java to Javascript code your variables. There are few ways:
I have created simple gwt maven project to show these ways. The project consists tests that are runned in build process and invoked javascript using HtmlUnit.
Project structure:
JsInterop class
MyClass:Class for global state
GlobalVariableExtensionNB:
namespaceisJsPackage.GLOBALandnameis"window"Our wrapper
PopupPanelJsWrapper:Test class
MainTestGwt:GwtMapsTestSuite:client.gwt.xml:test.gwt.xml:pom.xml: