Reputation: 19
I have write my own dialog and on my Index page have a AjaxLink when AjaxLink is clicked. I will behave to open my dialog instance. this is my code
add(new AjaxLink("open.working.date.dialog") {
@Override
public void onClick(AjaxRequestTarget target) {
WorkingDateDialog dialog = new WorkingDateDialog("working.date.dialog", getString("index.working.date.dialog.title"), true);
Index.this.add(dialog);
dialog.open(target);
}
});
of course, on my web page html markup I don't have reference component id working.date.dialog and it will throw exception. but when I replace Index.this.add(dialog); by this.add(dialog); or by target.add(dialog); the dialog won't work. There any other way to add dynamically dialog to page? In jquery I can do that easily by just append dialog html to body then open it by jquery. thanks for your all helpful!
Upvotes: 0
Views: 160
Reputation: 1588
You are going against the wicket way of doing things here, which will cause you much pain. :-) First of all WorkingDateDialog needs to extend ModalWindow. Assuming it does, here are my suggestions.
Right above your ajax link add this code:
final WorkingDateDialog dialog = new WorkingDateDialog("working.date.dialog", getString("index.working.date.dialog.title"), true);
add(dialog);
Then your ajax link becomes:
add(new AjaxLink("open.working.date.dialog") {
@Override
public void onClick(AjaxRequestTarget target) {
dialog.show(target);
}
});
So you always add your ModalWindow instance to your page hierarchy. It' just not visible until someone clicks the link.
I hope this helps you. Please let me know if you have any questions.
Upvotes: 0
Reputation: 17513
One option is to add the dialog in the constructor of the page and hide it initially. Then later when clicking the link just mark it as visible and add it to the AjaxRequestTarget.
Another option is to add a dummy/empty WebMarkupContainer with the same component id and later replace it with the dialog in #onClick().
Upvotes: 1