0
JavaFX WebView WebEngine setCreatePopupHandler - Popup executing JSP scriptlet java code twice.

Popup loads all HTML content and required results. Everything's fine, but I can see system out twice on the console on loading the popup.

And the same JSP, if I load independently

webEngine.load("http://localhost:8080/popup");

console prints only one system out.

"Why I am loading twice in Works ??"

But loading as popup, console prints twice.

"Why I am loading twice in Works ??"
"Why I am loading twice in Works ??"

Tried on all versions of JFX.

public class WebViewSample extends Application
{
 //Call Browser
 //Bla
}

public class Browser extends Region{
   //Bla bla 

    WebView browser = new WebView();
    WebEngine webEngine = browser.getEngine();

    webEngine.setCreatePopupHandler(popupFeatures -> createPopupWebViewCallbackHandler());

        private WebEngine createPopupWebViewCallbackHandler()
        {
            Stage stage = new Stage(StageStyle.UTILITY);
            WebView wv2 = new WebView();
            VBox vBox = new VBox(5);
            vBox.getChildren().add(wv2);
            wv2.getEngine().setJavaScriptEnabled(true);
            stage.setScene(new Scene(vBox));
            stage.show();
            return wv2.getEngine();
        }

     webEngine.load("http://localhost:8080/parent");
}

Parent jsp:

<head>
    <script type="text/javascript">
        function showUsersWindow() {
            window.open("/popup", "", "toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,width=500, height= 500");
        }
    </script>
</head>

<body>
        <div>
            <%
                System.out.println("I am Parent"); //Prints once in console, it is good.
            %>
            Try me :
            <button onclick="event.preventDefault();javascript:showUsersWindow();">Open</button>
        </div>
</body>

My new popup window jsp calling from the parent is popup.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <%
        System.out.println("Why I am loading twice in Works ??"); //Prints twice in console, wrong, should print only once.
    %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <div>I am popup</div>
</body>
</html>

Expecting on pop-up jsp scriptlet tag java code should execute once.

ram
  • 1
  • 3
  • According to the code you posted, you are embedding JavaFX `WebView` component in a _Swing_ application. Have you tried using a pure JavaFX app? Also you wrote: _Tried on all versions of JFX_ Pardon my ignorance, but can you give details of the versions you have tried? – Abra Jul 24 '19 at 16:01
  • @Abra, Yes. Tried pure JavaFX. I mean all versions up to JavaFX 11. 12 and not beta 13. I am using JavaFXPanel with WebView to load JSP. Ignore the swing at this moment. I am editing the above popup handler block on the above. – ram Jul 25 '19 at 06:55
  • Resolved the issue using Thread safe directive in JSP. To avoid thread conflicts with WebView engine rendering. – ram Sep 16 '19 at 14:12

0 Answers0