How do you call Java-method from JavaScript?



  • Reading the documentation here: http://code.google.com/webtoolkit/doc/1.6/FAQ_Client.html#How_do_I_call_Java_methods_from_handwritten_JavaScript_or_third ♪ But I still don't understand how to do the following:

    public static native void testBeforePaste(Element e, Runnable handler)  /*-{
      e.onbeforepaste = function() {
    

    // хочется, чтобы здесь был вызов handler.run();

    };
    }-*/;



  • If you want to be correct. (although it's too strong a word) Processing paste eventI don't need it. JSNI

    Should be traced from the class to which it is directed paste event (e.g. TextBox) Next, in a new class designer, sink relevant eventI mean, write sinkEvents(Event.ONPASTE) and reload the relevant processor onBrowserEvent:

    public void onBrowserEvent(Event event) {
        super.onBrowserEvent(event);
    
    switch (event.getTypeInt()) {
        case Event.ONPASTE: {
            // Соответствующая обработка.
            break;
        }
    }
    

    }


    A little comment about why "correct" is a strong word.

    Crossbrouserous solution (with some limitations) for all browsers except Opera.

    Thus, if there is an opportunity to avoid working with the relevant event'амиI think we should. Details Opera You can see. http://www.quirksmode.org/dom/events/cutcopypaste.html



    Update: I didn't see what. onbeforepaste (please tell me why you needed this)

    In that case, straight away. JSNI Don't bother:

    public native void addOnBeforePasteHandling(Element element) /*-{
    // Поскольку дальше используется замыкание.
    var thisHolder = this;

        element.onbeforepaste = function(e) {
            thisHolder. /users/2294/org .package.YourClass::handleOnBeforePaste()();
        }
    }-*/;
    

    public void handleOnBeforePaste() {
    Window.alert("onbeforepaste");
    }

    Parameters can be left to your discretion.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2