Search code examples
javagwtjsni

Pass value from GWT to Javascript via JSNI


I've been trying to pass a value into a Javascript method through JSNI but it keeps on failing.

Is this method valid:

public static native JavaScriptObject getProductById(long pid) /*-{
    var productId = pid;
    var product = $wnd.products({id:productId}).first();    
    return product;
}-*/;

I can say that the JS method is correct, since if I put a constant value in place of productId, I get the correct output.

What am I missing?


Solution

  • JSNI does not allow using long as input variable, see explanation here.

    You could try using double (or even int) instead, but make sure that your Javascript code supports it.

    public static native JavaScriptObject getProductById(double pid) /*-{
        var productId = pid;
        var product = $wnd.products({id:productId}).first();    
        return product;
    }-*/;