I am working on JavaFX 2.2, I use webview to integrate the html code into the JavaFX scene and was able to load the html correctly. I followed this link and tried to pass some objects from javascript to webview / controller, but I get null values โโfrom the java side.
I saved the interface object in JSObject as shown below
webEngine.getLoadWorker().stateProperty().addListener( new ChangeListener<State>() { @Override public void changed(ObservableValue<? extends State> ov, State oldState, State newState) { if (newState == State.SUCCEEDED) { JSObject win = (JSObject) webEngine.executeScript("window"); win.setMember("app", new JavaApp()); } } } );
I created a class
public class JavaApp { public void exit() { Platform.exit(); } public void print(Date date) { System.out.println("Parm:"+date); } public Date getValue() { return new Date(); } }
My html
<html lang="en"> <head> <script type="text/javascript"> function callJava(){ app.print(new Date()); var val = app.getValue(); app.print(val); } </script> </head> <body> <p>Help</p> <p><a href="about:blank" onclick="callJava();">Exit the Application</a></p> </body> </html>
In the above code, I always get null values โโprinted in the JavaApp.print () method. An interesting point is that I changed the Date parameter to String in the print method and passed the string from javascript, I get the correct values.
How can I pass objects in this case, especially a Date object. Any help is ambiguous
source share