Questions tagged [jsni]

JSNI is a means to include raw JavaScript code in a GWT application written in Java. JSNI is the web equivalent of inline assembly code.

JSNI (JavaScript Native Interface) can be used to integrate GWT with an existing JavaScript library, or to access low-level browser functionality not exposed by the GWT class API's. JSNI allows you to integrate JavaScript directly into your application's Java source code.

A JSNI method is declared native and contains JavaScript code in a specially formatted comment block between the end of the parameter list and the trailing semicolon. JSNI methods are called just like any normal Java method, and can accept parameters, call methods on Java objects, and return values to the Java-side of the application.

class JavaScriptCalculator 
{
  public static native int add(int n, int m) 
  /*-{ return n + m; }-*/;

  public static void main(String[] args)
  {
    System.out.println(JavaScriptCalculator.add(4, 8));
  }
}

The names $wnd and $doc are used to access the browser's window and document objects from JSNI.

public static native void say(String message) 
/*-{ $wnd.alert(message); }-*/;
365 questions
0
votes
2 answers

How to fix "Illegal method name $" error in GWT?

I followed all advices on http://google-web-toolkit.googlecode.com/svn/trunk/distro-source/core/src/doc/helpInfo/jsoRestrictions.html and still get the infamous $ error. The following statement triggers the error: final OpenCTM ctm =…
letmaik
  • 3,348
  • 1
  • 36
  • 43
0
votes
1 answer

Returning value from gwt to javascript-jsni

I am trying to return a value from java function in GWT to javascript via JSNI static public int call() { return 20; } public static native int jstest() /*-{ try{ val=@com.xxxx.package::call()(); …
Rangesh
  • 728
  • 2
  • 12
  • 27
0
votes
2 answers

Referencing JavaScript library in GWT for JavaScript Code

I'm using the d3.js library and have some javascript code written that already draws the animation I want. For the sake of simplicity/ size, say I want to use this sample source code. I'm trying to use GWT to build a richer user interface around the…
Josh Bradley
  • 4,630
  • 13
  • 54
  • 79
0
votes
3 answers

Calling a javascript function out of java

Im trying to call a javascript function out of my Vaadin Portlet. lets say I have an HTML file witch is located in my project ; homepage.html ...