I want to add a javascript library in my page each time when we click on a AjaxLink in apache wicket without refreshing the page. Is it possible to add Javascript library without refreshing the page and trigger that library each time on a function call ?
//Here , MetaModelPagePanel trigger and add a javascript file and create a graph using this
RepeatingView graphTesting1= new RepeatingView("graphTesting");
MetaModelPagePanel graphTesting = new MetaModelPagePanel(graphTesting1.newChildId(), getRepositoryKey());
graphTesting1.add(graphTesting.setVisible(false));
OverViewpanel.add(graphTesting1);
AjaxLink onClickGraph_Container = new AjaxLink<>("onClickGraph_Test") {
@Override
public void onClick(AjaxRequestTarget target) {
MetaModelPagePanel graphTesting = new MetaModelPagePanel(graphTesting1.newChildId(), getRepositoryKey());
graphTesting1.add(graphTesting);
OverViewpanel.add(graphTesting1.setVisible(true));
}
};
I'd recommend you to include the library just once and call it as many times as needed.
To include the library just add it as a dependency of any Component that is used:
The in your AjaxLink#onClick() just call it:
where
param1andparam2are just a demo of how you could pass any arguments to your function calculated for each click of the link.