Let's say that I have a RepeatingView with complex elements (for example containing applets). I want to add (or delete) a new element to RepeatingView with ajax, but I don't want to refresh all the elements, because it would cause applets to reload, which I obviously don't want.
I am using wicket 1.4.18
Adding to target only the element that I want to add, does not work, I get:
Component with id (...) was not found while trying to perform markup update. Make sure you called component.setOutputMarkupId(true) on the component whose markup you are trying to update
Take a look at the approach suggested in this Wicket in Action article: Repainting only newly-created repeater items via ajax
The problem when you want to add a new element via AJAX is that there's no root markup tag for the newly added item for Wicket to repaint it.
Quoting the article:
The trick is to give Wicket a tag to repaint via Ajax which can be
accomplished by doing the following:
- create the markup tag to represent the new item
- add it to the right place in the markup
- have Wicket repaint it via Ajax
The code in the article basically prepends some javascript in the ajax submit button's callback that actually creates the markup with the appropriate id for Wicket to be able to replace the element later, when you add it to the AjaxRequestTarget
.