Note that there are some explanatory texts on larger screens.

plurals
  1. POPossibility to call nonstatic gwt java method from javascript
    primarykey
    data
    text
    <p>General Aim: call some nonstatic java method from javascript</p> <p>Description: To find gwt's widget on DOM in Java Applet code and call it's java method(non static)</p> <pre><code> JSObject win = JSObject.getWindow(this); JSObject doc = (JSObject) win.getMember("document"); JSObject gwtWidget = (JSObject) doc.call("getElementsByName", widgetName); //todo: have possibility to call `exported` java method over here, smth like: //Object[] params = new Object[1]; //params[0] = widgetName; //Object result = gwtWidget.call("exportedJavaMethod", params); //todo: or just call global ($wnd) static JSNI bridge method: //Object result = win.call("exportedJavaMethod", params); // </code></pre> <p>The problem is: I can find by widget's id not the widget, but it's DivElement which does not have any exported instanced methods.</p> <p>My widget class is Exportable (gwt-export):</p> <pre><code> @Export(value="somewidget") public class SomeWidget extends SimplePanel implements ..., Exportable { private final String id = "id_some_widget_" + count++; private static int count = 0; public SomeWidget () { getElement().setAttribute("name", id); getElement().setId(id); } ... public static Element getInstanceById(String elementId) { Element someWidget= DOM.getElementById(elementId); return someWidget; } public String getSomeInstancedData() { return "useful_inner_data" + this.id; } </code></pre> <p>So, for example I'd like to find the concrete widget added to DOM and call nonstatic method <code>getSomeInstancedData()</code> in javascript. Is it possible at all?</p> <p>Suppose smth like:</p> <pre><code> var someWidget = document.getElementById(widgetId); alert(someWidget.getSomeInstancedData()); //or: var someWidgetExported = com.mypackage.widgets.somewidget.getInstanceById(listenerId); alert(someWidgetExported.getSomeInstancedData()); </code></pre> <p>In Base module I write:</p> <pre><code> ExporterUtil.exportAll(); </code></pre> <p>There is a View(ViewWithSomeWidget.ui.xml) that contains this widget:</p> <pre> ... base:Form base:SomeWidget ui:field="someWidget" ... ... /base:SomeWidget ... </pre> <p>When SomeWidget does not implement Exportable, project runs well, but I couldn't call nonstatic methods of found widget's DIV element.</p> <p>By the time, to solve the problem SomeWidget implements Exportable, but progect doesn't show View with the SomeWidget well because of ClassCastException using deferred binding:</p> <pre><code> ClassCastException: com.mypackage.widgets.SomeWidgetExporterImpl cannot be cast to com.mypackage.widgets.SomeWidget </code></pre> <p>So, probably there are any other methods to find widget's javascript object and call it's exported java method? In any ways, any idea is much appreciated. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload