ThunderWolf
ThunderWolf

Reputation: 130

JavaFX JavaScript upcall with arguments

I need to know how to up-call from JavaScript to JavaFX with arguments. Some sample code:

JSObject script = (JSObject) webEngine.executeScript("window");
script.setMember("app", SignIn(arg1, arg2));

private boolean SignIn(String uid, String passwd) {
        boolean signedIn = false;
        System.out.println("Signing In");
        return signedIn;
}

html

<html>
<body>
<a onclick="app.SignIn(uid, passwd)">Click to sign in</a>
</body>
</html>

This code does not work.

Upvotes: 1

Views: 1598

Answers (1)

Uluk Biy
Uluk Biy

Reputation: 49195

The line

script.setMember("app", SignIn(arg1, arg2));

seems to be wrong. Try

script.setMember("app", new SignInManager());

where SignInManager is a class containing your SignIn(String uid, String passwd) method. You can make an analogy on this line like:

app = new SignInManager();

then use it in javascript code

app.SignIn(uid, passwd)

on click event. So (as a reply to your comment below) you are actually passing parameters from javascript code to Java code here.

By convention the method names should be started with lower case as signIn(String uid, String passwd).

Upvotes: 1

Related Questions