Reputation: 23
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));
}
};
Upvotes: 0
Views: 58
Reputation: 17533
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:
@Override
public void renderHead(Component component, IHeaderResponse response) {
response.render(JavaScriptHeaderItem.forReference(MyPanel.class, "my-library.js"));
}
The in your AjaxLink#onClick() just call it:
@Override
public void onClick(AjaxRequestTarget target) {
...
target.appendJavaScript("myLibrary.doSomething('"+param1+"', '"+param2+"')");
}
where param1
and param2
are just a demo of how you could pass any arguments to your function calculated for each click of the link.
Upvotes: 0