Description
Created a Panel that provides it's own dynamically created markup stream, scans that stream for wicket:ids, and adds different components based on the id. Recently, I've been wanting to redraw this panel via AJAX, changing the markup and adding and removing child components accordingly.
I tried to remove multiple stale components (e.g. a component that was generated from the previous markup but doesn't exist in the new markup) using an IVisitor..
visitChildren(new IVisitor<Component>() {
public Object component(Component component) {
if (/* component is stale */)
component.remove();
return CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
}
The IVisitor just does a simple run through an array and removing the component adjusted the size/count of the array, messing up the traversal and preventing other components from being removed.
Potential Solutions:
1. Throw an exception if the hierarchy is modified in an IVisitor.
2. Use another means of traversing the children that allows addition/removal and still ensures visiting all the children.