0

I use javafx & webview to load a delegated UI in new stage in an iframe. the page contain paginated table with checkbox,which the selected Items will be send back to my listener as json format.delegated UI provided by the server and I have no access to the source.as far as I know delegated page use dojo library.

problem is that when clicking on the page number and selecting multiple items, sometimes when pressing OK button, it will not send data to my listener and it seems no event is working anymore as the cancel button also not send back event, but the drawer menue is working(if it use kind of script). the window must be reopen to work again.

here is a snippet of how the page will be loaded:

private void openWebViewWindow(String url) {

        ....

        webViewStage = new Stage();
        WebView webView = new WebView();
        WebEngine webEngine = webView.getEngine();

        // Enable JavaScript support
        webEngine.setJavaScriptEnabled(true);


        // Ignore SSL certificate validation
        ignoreCertificateValidation();

        // Load a blank page first
        webEngine.loadContent("");

        // Authenticate the user
        authenticateUser(webEngine);

        // Create the iframe HTML code
        String iframe = "<div><iframe id=\"myIframe\" src=\"" + url + "\" width=\"1024\" height=\"800\"></iframe></div>";
        iframe = "<html><head></head><body><div><iframe id=\"myIframe\" src=\"" + url + "\" width=\"1024\" height=\"800\"></iframe></div></body></html>";

        // Attach a Console object to intercept console messages
        webEngine.setOnError(event -> {
            System.err.println("Web Engine Error: " + event.getMessage());
        });


        // Add a JavaScript interface to the webEngine
        webEngine.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> {
            if (newValue == Worker.State.SUCCEEDED) {
                JSObject window = (JSObject) webEngine.executeScript("window");
                window.setMember("javaAppListener", new ListenerClass());
                webEngine.executeScript("window.addEventListener('message', function(event) { "
                        + "javaAppListener.processEvent(event.data);" + "});");

            }
        });


        // Create the scene and show the stage
        Scene webViewScene = new Scene(webView, 1024, 800);
        webViewStage.setScene(webViewScene);
        webViewStage.show();


        // Load the iframe content into the WebView
        if(url.endsWith("condition")) {
            webEngine.load(url);
        }
        else {
            webEngine.loadContent(iframe);
        }
...

    }

I Tried loading the page with and without iframe, as it is says that the delegated page must be wraped in ifram as it transfer data using postMessage/windowName protocol. both case has the same issue I used it with jdk 1.8 and 11, both has the same result. attempted to debug it by injecting firebug How to debug JavaFX webview in 2022, but firebug did not loaded finally i could inject firebug into loaded page but i could not use the inspector or console to find a clue as firebug did not show scripts as of "access to restricted URI" :( Also tried to use setOnAlert and exceptionProperty events but they did not return any warning or errors.

Thank you in advance

mjr
  • 165
  • 1
  • 9
  • such a lucky guy am I!‍♂️ after long time I asked a question in stackoverflow and it was in the middle of a Strike ⚔️. Good luck then! :) – mjr Jun 15 '23 at 07:53

0 Answers0