0

I need execute script from file myFunctions.js in javafx Webengine and send info to server with resttemplate:

public void onDeviceStatusChanged(DeviceStatusEvent deviceStatusEvent) {

        String uri = defaultPage + "my/" + "devices/status";

        if (deviceStatusEvent.getDevStat().getDev() == 0) {
            webEngine.executeScript("billAcceptorStatus(" + deviceStatusEvent.getDevStat().getStatus() + ")");
        }
        if (deviceStatusEvent.getDevStat().getDev() == 1) {
            webEngine.executeScript("posPrinterStatus(" + deviceStatusEvent.getDevStat().getStatus() + ")");
        }
        if (deviceStatusEvent.getDevStat().getDev() == 2) {
            webEngine.executeScript("cardReaderStatus(" + deviceStatusEvent.getDevStat().getStatus() + ")");
        }
        if (deviceStatusEvent.getDevStat().getDev() == 4) {
            webEngine.executeScript("pinPadStatus(" + deviceStatusEvent.getDevStat().getStatus() + ")");
        }
        try {
            if (deviceStatusEvent.getDevStat().getDev() == 0) {
                if (deviceStatusEvent.getDevStat().getStatus() == 2) {
                    HttpEntity request = new HttpEntity<>(defaultHeaders.getMap());
                    String string = restTemplate.postForObject(defaultPage + "/my/" + "devices/ink", request, String.class);
               }
            }

            HttpEntity<SimpleDevStat> request = new HttpEntity<>(deviceStatusEvent.getDevStat(), defaultHeaders.getMap());
            restTemplate.postForLocation(uri, request);
            log.debug("Posted : " + deviceStatusEvent.getDevStat());
            webEngine.executeScript("networkStatus(true)");
        } catch (Exception e) {
            webEngine.executeScript("networkStatus(false)");
            e.printStackTrace();
        }
    }

If myFunctions.js is not loaded to webengine, webengine.executeScript() not worked and code stop this line. I need check exists myFunctions.js in webengine. How to check js file in webengine?

Saahon
  • 404
  • 1
  • 6
  • 27
  • You could check this thread out: http://stackoverflow.com/questions/32429069/loading-local-javascript-file-in-webview-in-java-8u60 – DVarga Jul 29 '16 at 09:27
  • @DVarga - Thanks, helped. I think in my case, this approach is not correct. I just need information about the latest status of the device. By this I will save the settings in json file, and when the js page opens, needed information read from json file. Json file will be stored in the user.home directory – Saahon Jul 29 '16 at 13:55

0 Answers0