Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is something like GWT JSNI supported? #138

Open
WhiteTrashLord opened this issue Nov 16, 2016 · 5 comments
Open

Is something like GWT JSNI supported? #138

WhiteTrashLord opened this issue Nov 16, 2016 · 5 comments
Labels

Comments

@WhiteTrashLord
Copy link

I want to write my own native Javascript code in my Java code. In GWT I can do it with JSNI.
STJS also supports it? I read the documentation and could not find anything like it.

@acraciun
Copy link
Member

If your JS code that you want to use is quite big, you'll only need to
write some interfaces in Java to allow your Java/ST-JS code use it - the
some way any of the ST-JS bridge is done.

But if you only want to code some small JS code directly you can do it with
the $js() method:
https://github.com/st-js/st-js/blob/master/shared/src/main/java/org/stjs/javascript/JSObjectAdapter.java#L78

On Nov 16, 2016 11:57 PM, "WhiteTrashLord" notifications@github.com wrote:

I want to write my own native Javascript code in my Java code. In GWT I
can do it with JSNI.
STJS also supports it? I read the documentation and could not find
anything like it.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#138, or mute the thread
https://github.com/notifications/unsubscribe-auth/ABgADcNdnyqdmo-GW_fZch7jbjiL3oQtks5q-4pJgaJpZM4K0lcL
.

@WhiteTrashLord
Copy link
Author

Thank you for your answer. I would use it only for short JS code. But I would also be able to define my own parameters. This is no supported by $js, or?

In TeaVM it can be done by something like this:

@JSBody(params = "message", script = "alert(message);")
public static native void alert(JSObject message);

This is much better than GWT JSNI in my opinion. It would be great if you can implement something like this :)

@acraciun
Copy link
Member

acraciun commented Jan 6, 2017

if you want with this construction to bridge the global alert method this is already done in https://github.com/st-js/html-bridge/blob/master/src/main/java/org/stjs/javascript/Global.java#L33

But if you have somewhere a global function called:
function myFunction(intParam, stringParam) {....}

it's enough to create a class

@GlobalScope
public class MyGlobals {
public static native void myFunction(int intParam, String stringParam);
}

no other annotations are needed.

Was this your intention?

@WhiteTrashLord
Copy link
Author

Thank you for your answer. It seems that this exactly what I was looking for :)

Is it also possible to give a method in Java a global scope?

So for example I would like to invoke such a method in the Javascript code only with "helloWorld()".

 public static void helloWorld()
 {			 
	 alert("Hello world");
 }

@acraciun
Copy link
Member

acraciun commented Apr 6, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants