I have a linktree for navigation over data which shall replace a component in another div.
For this in the tree I have the treestatelistener implementing
public void nodeSelected(Object node) {
log.debug("nodeSelected: " + node+ " class: " + node.getClass());
Component content = new Label("content");
content.replaceWith(new Label("content", "Hello World"));
}
}
}
All I get is the message:
“This method can only be called on a component that has already been
added to its parent.”
The Label with Id “content” is added to the page on init, so it is there before. What do I do wrong?
I always have issues with just calling Component.replaceWith(). Since I am doing this with AJAX, I always need to call a target.add().
My solution is for now to have a class MyTree extend LinkTree and in that class override the newNodeComponent().
Since in my application everything happens on the IndexPage.class and there I just replace components, I added a method handleSelection() to the IndexPage.Class(extends BasePage extends webpage). There I decide, based on the clicked nodeObject, how to replace a component in the IndexPage
I hope this is explained propperly, else: questions or comments wanted!