JavaFX Webview: Download succeeds

I have a Webview (JavaFX 8) that downloads a Wikipedia article.

I put the refresh button to enable the update, basically it makes another call to the webEngine WebView download method with the same URL. But in about 50% of cases, an article is never displayed. In this case, I can right-click on the web view to update manually, after which it will succeed.

I tried to see the state of LoadWorker, it always says "SUCCEED" ...

Below is a short test class that demonstrates my point.

public class Test1 extends Application { @Override public void start(Stage primaryStage) throws Exception { final WebView webView = new WebView(); webView.getEngine() .load("http://fr.wikipedia.org/wiki/Sp%C3%A9cial:Page_au_hasard"); Tab tab = new Tab("webView", webView); TabPane tabPane = new TabPane(tab); BorderPane borderPane = new BorderPane(tabPane); Button buttonRefresh = new Button("Refresh"); buttonRefresh.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { webView.getEngine() .load("http://fr.wikipedia.org/wiki/Sp%C3%A9cial:Page_au_hasard"); } }); borderPane.setBottom(buttonRefresh); Scene scene = new Scene(borderPane); primaryStage.setScene(scene); primaryStage.show(); } public static void main (String[] args) { launch(args); } 

}

Am I doing something wrong? Does anyone know where this problem might come from?

EDIT

I added a few lines to get around the problem, I check the header in the DOM when the state of loadWorker becomes SUCCESS. If it is empty, I reboot. Now it (looks) 100% good, but still I’m very curious why it didn’t just work all the time in the first place.

Some thoughts that may be helpful

  • The link http://fr.wikipedia.org/wiki/Sp%C3%A9cial:Page_au_hasard redirects to a random article (therefore, my update button cannot use webView.getEngine.reload() ).
  • Actually, the ChangeListener add-in runs on the stateProperty of the working Loader to invoke the webEngine reload method. Each page is displayed successfully, but the page that is already displayed will also be redrawn, which is terrible.
+5
source share

All Articles