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.