Javafx 8上的WebView问题

时间:2017-02-10 19:16:43

标签: webview javafx-8

我遇到了WebView组件的问题。有时,如果应用程序保持空闲状态几分钟,则显示屏只是一个空白屏幕,并且WebView不会在舞台上呈现。其他时候它完美无缺。此外,一旦特定的webView组件无法呈现到屏幕上,整个应用程序中的所有其他webView都无法加载。

该组件行为非常不一致,我无法确定复制问题的确定模式。

我很感激,如果你们中的任何一位专家能指出我正确的方向来解决这种不一致的行为。

我的WebView代码:

String htmlBillText = billTextController.transformBillXmlXsl();

WebView webView = new WebView();
WebEngine engine = webView.getEngine();
engine.setOnError((WebErrorEvent event) -> {
    // NEVER GOES INTO THIS AT ALL
    System.out.println("event.getMessage()::"+event.getMessage());
    System.out.println("event.getException()::"+event.getException().getMessage());
    System.out.println("event.toString()::"+event.toString());
    engine.reload();
});

engine.getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>() {
    @Override
    public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) {

        System.out.println("oldState::" + oldState);
        System.out.println("newState::" + newState);
        if (engine.getLoadWorker().getException() != null) {
            System.out.println("engine.getLoadWorker().getException()::" + engine.getLoadWorker().getException().getLocalizedMessage());
        }

        if (engine.getLoadWorker().getException() != null && newState == Worker.State.FAILED) {
            System.out.println(engine.getLoadWorker().getException().getMessage());
        }

        if (newState == Worker.State.SUCCEEDED) {
            System.out.println("engine.getDocument()::"+engine.getDocument());
            if (engine.getDocument() != null) {
                String html = (String) engine.executeScript("document.documentElement.innerHTML");
                if (StringUtils.isEmpty(html)) {
                    System.out.println("FX WebView Engine Failed To Load Content... Execute Reload...");
                    engine.reload();
                }
            }
            System.out.println("engine.getTitle()::" + engine.getTitle());
            System.out.println("engine.getLocation()::" + engine.getLocation());
            System.out.println("engine.getUserAgent()::" + engine.getUserAgent());
            System.out.println("engine.getUserDataDirectory()::" + engine.getUserDataDirectory());
            System.out.println("engine.isJavaScriptEnabled()::" + engine.isJavaScriptEnabled());
        }
    }
});
engine.loadContent(htmlBillText);

WEBVIEW失败时我的显示控制台:

oldState::READY
newState::SCHEDULED
oldState::SCHEDULED
newState::RUNNING
oldState::RUNNING
newState::SUCCEEDED
engine.getDocument()::[object HTMLDocument]
engine.getTitle()::SB6:v98#DOCUMENT
engine.getLocation()::
engine.getUserAgent()::Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/538.19 (KHTML, like Gecko) JavaFX/8.0 Safari/538.19
engine.getUserDataDirectory()::null
engine.isJavaScriptEnabled()::true

感谢任何帮助。谢谢-Sv

1 个答案:

答案 0 :(得分:0)

已经出现了一个错误,可以在下面跟踪进度:

https://bugs.openjdk.java.net/browse/JDK-8175170

感谢。 -SV