Search code examples
javajavascriptgwtjsnicodemirror

GWT JSNI method with native JS: "Invalid Label"


Maybe my question is simple to solve for you, but I'm sitting here for a few hours with following problem (and I have already searched for it):

I have a Java method which has JavaScript code inside (JSNI from Google's GWT) to set key bindings for the code editor CodeMirror2. When I want to compile with GWT, I'm getting an error from the GWT compiler:

[ERROR] Line 195: invalid label
> "F11": function() {

My code looks like this:

public final native void setExtraKeysCallback() /*-{
    this.extraKeys = function(editor) {
        "F11": function() {
            // do something
        },
        "Esc": function() {
            // do something
        }
    };
}-*/;

The really strange thing is that in native JS the extra keys are working with this syntax?! I think the problem is the label syntax, how could I change this to work with GWT?

Thanks, leX


Solution

  • You seem to be mixing object literal syntax:

    { "key": value, "key2", value2 }
    

    … with function expression syntax:

    function () { }
    

    Decide if you are trying to create a simple object or a function (or a function that returns a simple object) and use the appropriate syntax for that.