Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8473489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:21:56+00:00 2026-06-10T17:21:56+00:00

General Aim: call some nonstatic java method from javascript Description: To find gwt’s widget

  • 0

General Aim: call some nonstatic java method from javascript

Description:
To find gwt’s widget on DOM in Java Applet code and call it’s java method(non static)


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);
//

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.

My widget class is Exportable (gwt-export):


@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;
    }

So, for example I’d like to find the concrete widget added to DOM and call nonstatic method getSomeInstancedData() in javascript. Is it possible at all?

Suppose smth like:


var someWidget = document.getElementById(widgetId);
alert(someWidget.getSomeInstancedData());

//or:
var someWidgetExported = com.mypackage.widgets.somewidget.getInstanceById(listenerId);
alert(someWidgetExported.getSomeInstancedData());

In Base module I write:


ExporterUtil.exportAll();

There is a View(ViewWithSomeWidget.ui.xml) that contains this widget:

...
base:Form
base:SomeWidget ui:field="someWidget" ...
...
/base:SomeWidget
...

When SomeWidget does not implement Exportable, project runs well, but I couldn’t call nonstatic methods of found widget’s DIV element.

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:


ClassCastException: com.mypackage.widgets.SomeWidgetExporterImpl cannot be cast to com.mypackage.widgets.SomeWidget

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:21:57+00:00Added an answer on June 10, 2026 at 5:21 pm

    You can declare a javascript function, which will fire the non-static method.

    For example:

    package com.example;
    public class Layout extends VLayout() {
        private String nonStaticVar = "nonStaticVar";
        public Layout() {
            declareMethod(this);
        }
    
        //Method which declares non-static method in javascript
        public native void declareMethod(Layout layout) /*-{
            var layout = layout;
            $wnd.doSomething = function(someString) {
                layout.@com.example.Layout::doSomething(Ljava/lang/String;)(someString);
            }
        }-*/;
    
        //Non static method which is being called
        public String doSomething(String someString) {
            //Do something, e.g. set var in this instantiated class, or output stuff
            this.nonStaticVar = someString;
            Window.alert(someString);
        }
    }
    

    Now, calling
    doSomething(“bla”);
    from javascript will call your non-static method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In general, is it reasonable to return None from a __new__ method if the
This is a general question concerning technology decisions for a product development. My aim
General wisdom is when you remove a component from the stage you also need
General javascript question here, which would also be good to know how(if possible) to
General approach in GWT is to use Panels and then apply custom CSS themes
General use case I am trying to implement a basic shell. Description I need
General question about java servlets and the best way to handle requests. If I
General Python Question I'm importing a Python library (call it animals.py) with the following
General question: is FB JS API should work on IE7 perfect? Every call should
General Description I implemented an OP (OpenID Provider), using DotNetOpenAuth . I am testing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.