Clearing current WebView Content and reloading a different content in JavaFX

177 Views Asked by At

I have a WebView which displays a HTML page, say MainGraph.html, and execute a javascript function with "false" as a parameter. On clicking one of the menuitems, I want the same javascript function to be called but now with "true" as the parameter.

When the menuitem is selected, there are two outputs of the same javascript instead of the latest one replacing the older one.

AnalysisController.java

public class AnalysisController implements Initializable {

  public void displayMainGraph(WebEngine weMainGraph, boolean pblnFishEyeLens) {
        System.out.println("AnalysisController.displayMainGraph(): Called");
        String strDataFile = strCurrentInputFile + ".json";
        final URL urlLoadMainGraph = getClass().getResource("html/MainGraph.html");                
        weMainGraph.getLoadWorker().stateProperty().addListener((ov, oldState, newState) -> {
            if (newState == State.SUCCEEDED) {
                weMainGraph.executeScript(" doEverything(' "+strDataFile+" ', "+pblnFishEyeLens+") ");
            }
        });
        weMainGraph.load(urlLoadMainGraph.toExternalForm());        
    }    
}

And MenuItemsFishEyeLens.java is the place where I would be invoking a function based on the MenuItem Click.

public class MenuItemFishEyeLens extends WelcomeMenuBar.MenuItemGeneric implements IMenuItem{

    public MenuItemFishEyeLens(String pstrMenuItemDisplay, String pstrMenuItemClass, String pstrMenuItemIconPath) {
        super(pstrMenuItemDisplay, pstrMenuItemClass, pstrMenuItemIconPath);
    }

    @Override
    public void Click(TabPane pTabPane, AnalysisController pController, boolean pblnSelected) {
        String strCallingMethod = "AnalysisMenuBar.MenuItemFishEyeLens.Click(): ";         
         pController.displayMainGraph(pController.getCurrentWebEngine(), pblnSelected);
        System.out.println(strCallingMethod+"END");
    }
}

When the MenuItem is clicked, the output shows two same graphs, first one with pblnFishEyeLens value = false and the second one with true. The output is

WelcomeMenuBar.MenuItemOpen.Click(): END

Thi is called with parameter: false

AnalysisController.displayMainGraph(): Called
displayMainGraph(): test1.meerkat FishEyeLens parameter: true
AnalysisMenuBar.MenuItemFishEyeLens.Click(): END
Thi is called with parameter: false
Thi is called with parameter: true
0

There are 0 best solutions below