javafx webengine fails to execute callback functions

Dan Source

So basically I have a webpage to whom I've linked JavaFX with, been running the app for a while everything performs fine(can execute java to javascript and vice versa), the only problem that I'm having now is that when I tried to execute a javascript function which has a callback function it is returning null values, I tried to put a button on the webpage and execute the same function IT EXECUTED FINE!! I'm confused! anyone facing the same issue or it's just me? Is it possible that JavaFX Web engine does not support callback functions?

so here is the javascript code for my webpage

function travellingTime(Origin,Destination,callback){
	var myVar;
	var directionsService = new google.maps.DirectionsService();
	var request = {
    origin: Origin,
    destination: Destination,
    travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function (response, status) {
    if (status == google.maps.DirectionsStatus.OK) {

        // Display the distance:
        //alert(response.routes[0].legs[0].distance.value + " meters");

        // Display the duration:
        //Time = (response.routes[0].legs[0].duration.value / 60);

     
    myVar = (response.routes[0].legs[0].duration.value / 60); 
                          
     callback(myVar);   
    }
	
});

}

javascript callback function that will be needed to get the "myVar" value

function getTime(myVar){app.setTime(myVar.toFixed(2));}

please note that "app" is set a class called "vehicleRoutingProblem" and I'm using method setTime() to set the time

class vehicleRoutingProblem (ignore the bad design, it's just for practices)

public static String time;


      public String getTime() {
    return time;
}

public void setTime(String time) {
    this.time = time;
}

Last I have my main class which i called class VehicleRoutingProblem to print the time

engine.executeScript("travellingTime('port louis','vacoas',getTime)");
VehicleRoutingProblem vpr = new VehicleRoutingProblem();
System.out.println("Travelling time to portlouis "+vpr.time);

Executing this with executeScript gave me

Travelling time to portlouis null

But with a button embedded in the page print the correct answer to the console

<button onclick="travellingTime('port louis','vacoas',getTime)">TSP</button>

javajavafxjavafx-webengine

Answers

comments powered by Disqus