-
Bug
-
Resolution: Won't Fix
-
P3
-
None
-
8u20
-
x86_64
-
windows_7
J2SE Version (please include all output from java -version flag):
java version "1.8.0_20-ea"
Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b20)
Java HotSpot(TM) Client VM (build 25.20-b20, mixed mode)
Does this problem occur on J2SE 7ux? Yes / No (pick one)
not known
Operating System Configuration Information (be specific):
Windows 7 Ultimate SP1
Hardware Configuration Information (be specific):
Amd 64 X2 4200+
Bug Description:
The javaFX upcalls from javascript contained in a web page to javaFX code
cause the page to be reloaded in Webengine.
Steps to Reproduce (be specific):
Create in Netbeans a project for the following java file:
package javafx2;
import javafx.application.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.scene.web.*;
import org.w3c.dom.*;
import org.w3c.dom.events.*;
import javafx.concurrent.Worker.State;
import javafx.beans.value.*;
import netscape.javascript.*;
public class JavaFXApplication2 extends Application {
Document doc = null;
@Override
public void start(Stage primaryStage) {
// create WebView with specified local content
WebView root = new WebView();
//root.getEngine().load(uri.toString());
final WebEngine we = root.getEngine();
we.getLoadWorker().stateProperty().addListener(
new ChangeListener<State>() {
public void changed(ObservableValue ov, State oldState, State newState) {
if (newState == State.SUCCEEDED) {
System.out.printf("changelistener\n");
doc = we.getDocument();
JSObject window = (JSObject) we.executeScript("window");
window.setMember("app", new JavaApplication());
}
}
});
root.getEngine().load("file:///D:/nodewebkit/webview/index.html");
root.setZoom(javafx.stage.Screen.getPrimary().getDpi() / 96);
primaryStage.setTitle("Test");
primaryStage.setScene(new Scene(root, 1100, 820));
primaryStage.show();
}
public class JavaApplication {
public void setspan() {
Element el = doc.getElementById("zzz");
try {
System.out.printf("setspan %s\n",el.getTextContent());
el.setTextContent("mmmm");
} catch(Throwable exc){
System.out.printf("!!!! %s\n",exc);
}
}
}
public static void main(String[] args) {
launch(args);
}
}
Use it to display this web page:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; id=zzz>aaaa</span>
<a href="" onclick="app.setspan()">Click here to change text</a>
</body>
</html>
(change then the URL in the root.getEngine().load() statement to reflect the
path were you put it).
Run then the project.
A window appears on the screen.
Click on the hyperlink.
You would see the text changed, and immediately after, the original text appearing
again.
On the Netbeans console, the following is displayed:
jfx-project-run:
Executing C:\Users\angelo\Documents\NetBeansProjects\JavaFXApplication2\dist\run852424879\JavaFXApplication2.jar using platform C:\Program Files\Java\jdk1.8.0_20\jre/bin/java
changelistener
setspan aaaa
changelistener
This shows that:
1. the changelistener is called (as a result of completing the loading of the document)
2. setspan is called (as a result of clicking on the hyperlink)
3. the changelistener is called again, probably as a result of reloading the document
This means that when the javascript onclick="app.setspan()" attached to the hyperlink is
executed, control is transferred to the webengine and then to the setspan() method of
the app class, but after executing it, the page is reloaded.
This is not the intended behaviour.
Note that setting the onclick event handler from within the changelistener makes webengine
behave correctly. I.e. when the user clicks on the hyperlink, the java method that implements
the event handler is executed and no page is reloaded.
This misbehaviour prevents web pages to make upcalls to javaFX code.
java version "1.8.0_20-ea"
Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b20)
Java HotSpot(TM) Client VM (build 25.20-b20, mixed mode)
Does this problem occur on J2SE 7ux? Yes / No (pick one)
not known
Operating System Configuration Information (be specific):
Windows 7 Ultimate SP1
Hardware Configuration Information (be specific):
Amd 64 X2 4200+
Bug Description:
The javaFX upcalls from javascript contained in a web page to javaFX code
cause the page to be reloaded in Webengine.
Steps to Reproduce (be specific):
Create in Netbeans a project for the following java file:
package javafx2;
import javafx.application.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.scene.web.*;
import org.w3c.dom.*;
import org.w3c.dom.events.*;
import javafx.concurrent.Worker.State;
import javafx.beans.value.*;
import netscape.javascript.*;
public class JavaFXApplication2 extends Application {
Document doc = null;
@Override
public void start(Stage primaryStage) {
// create WebView with specified local content
WebView root = new WebView();
//root.getEngine().load(uri.toString());
final WebEngine we = root.getEngine();
we.getLoadWorker().stateProperty().addListener(
new ChangeListener<State>() {
public void changed(ObservableValue ov, State oldState, State newState) {
if (newState == State.SUCCEEDED) {
System.out.printf("changelistener\n");
doc = we.getDocument();
JSObject window = (JSObject) we.executeScript("window");
window.setMember("app", new JavaApplication());
}
}
});
root.getEngine().load("file:///D:/nodewebkit/webview/index.html");
root.setZoom(javafx.stage.Screen.getPrimary().getDpi() / 96);
primaryStage.setTitle("Test");
primaryStage.setScene(new Scene(root, 1100, 820));
primaryStage.show();
}
public class JavaApplication {
public void setspan() {
Element el = doc.getElementById("zzz");
try {
System.out.printf("setspan %s\n",el.getTextContent());
el.setTextContent("mmmm");
} catch(Throwable exc){
System.out.printf("!!!! %s\n",exc);
}
}
}
public static void main(String[] args) {
launch(args);
}
}
Use it to display this web page:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; id=zzz>aaaa</span>
<a href="" onclick="app.setspan()">Click here to change text</a>
</body>
</html>
(change then the URL in the root.getEngine().load() statement to reflect the
path were you put it).
Run then the project.
A window appears on the screen.
Click on the hyperlink.
You would see the text changed, and immediately after, the original text appearing
again.
On the Netbeans console, the following is displayed:
jfx-project-run:
Executing C:\Users\angelo\Documents\NetBeansProjects\JavaFXApplication2\dist\run852424879\JavaFXApplication2.jar using platform C:\Program Files\Java\jdk1.8.0_20\jre/bin/java
changelistener
setspan aaaa
changelistener
This shows that:
1. the changelistener is called (as a result of completing the loading of the document)
2. setspan is called (as a result of clicking on the hyperlink)
3. the changelistener is called again, probably as a result of reloading the document
This means that when the javascript onclick="app.setspan()" attached to the hyperlink is
executed, control is transferred to the webengine and then to the setspan() method of
the app class, but after executing it, the page is reloaded.
This is not the intended behaviour.
Note that setting the onclick event handler from within the changelistener makes webengine
behave correctly. I.e. when the user clicks on the hyperlink, the java method that implements
the event handler is executed and no page is reloaded.
This misbehaviour prevents web pages to make upcalls to javaFX code.