3 Replies Latest reply: Jun 6, 2013 8:49 AM by 1005510 RSS

    ManagerBean and Web Server VS simple browser and controller class on JavaFX

      Good afternoon,

      Please I want to know if it is possible to do the following.
      I have a small JavaFX application and in one of the interfaces I have a browser and I load on it a map from google maps.
      I want that the information in the map to be loaded from the database each x seconds.
      If I make a thread and a loop in the controller class, the interface is blocked because the condition of the loop is true.

      The solution is possible with managedBean and glassfish like on this script that is contained in an xhtml page
      the function CarOnTime is executed each 2 seconds and calls a ManagedBean
            <script type="text/javascript">
                                              var latlng = new google.maps.LatLng(35.857908, 10.598997);
                                              var Options = {
                                                  zoom: 15,
                                                  center: latlng,
                                                  mapTypeId: google.maps.MapTypeId.ROADMAP
                                              var map = new google.maps.Map(document.getElementById("map_canvas"), Options);
                                              var carMarkerImage = new google.maps.MarkerImage('resources/images/car.png');
                                              var marker = new google.maps.Marker({
                                                  position: new google.maps.LatLng(35.857908, 10.598997),
                                                  map: map,
                                                  draggable: false,
                                                  //icon: carMarkerImage,
                                                  title: "Car on Time",
                                                  autoPan: true
                                              var infobulle = new google.maps.InfoWindow({
                                                  content: "Le service n\'est pas disonible !!"
                                              google.maps.event.addListener(marker, 'mouseover', function() {
                                                  infobulle.open(map, marker);
                                              function carOnTime() {
                                                  $.ajax({url: "getCarsGeo", context: document.body})
                                                          .done(function(data) {
                                                      vars = data.split("|");
                                                      marker.setPosition(new google.maps.LatLng(vars[2], vars[3]));
                                                      map.setCenter(new google.maps.LatLng(vars[2], vars[3]));
                                                      infobulle.content = "Le matricule est : " + vars[0];
                                                  setTimeout("carOnTime()", 2000);
      this is what I have done, with thread and the interface is blocked when executing.
      public class OnTimeController implements Initializable {
          MyBrowser myBrowser;
          WebEngine we;
          double latitude;
          double longitude;
          Service service;
          Client client;
          private AnchorPane anchorMap;
          String selectedCarId = "1";
          public void initialize(URL url, ResourceBundle rb) {
              myBrowser = new MyBrowser();
              we = myBrowser.getWebEngine();
              FxThread t = new FxThread();
                  try {
                  } catch (InterruptedException ex) {
                      Logger.getLogger(OnTimeController.class.getName()).log(Level.SEVERE, null, ex);
          public void getOnTime() {
              System.out.println("THREAD EXECUTE");
              service = new Service("http://" + model.getAddIP() + ":8080/ServerGeoTrack/webresources", "authlogin/getParamOnTimeByCarId/" + selectedCarId, client);
              List<Paramontime> lp = service.getParamOnTimeByCarId();
              latitude = lp.get(0).getLatitude();
              longitude = lp.get(0).getLongitude();
              we.getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>() {
                  public void changed(ObservableValue<? extends Worker.State> ov, Worker.State t, Worker.State t1) {
                      we.executeScript("goToLocation(" + latitude + "," + longitude + ")");
          public class FxThread extends Thread {
              public void run() {
                  Platform.runLater(new Runnable() {
                      public void run() {
             class MyBrowser extends Region {
                  HBox toolbar;
                  WebView webView = new WebView();
                  WebEngine webEngine = webView.getEngine();
                  public WebEngine getWebEngine() {
                      return webEngine;
                  public MyBrowser() {
                      final URL urlGoogleMaps = getClass().getResource("googlemaps.html");
      Is there annother solution with threads or a solution similar of using managedBeans, or calling the controller class and its method from the script.
      Thank you