Apache wicket:来自 Linktree.onNodeSelected() 的 Componenet.replaceWith(component)
我有一个用于导航数据的链接树,它将替换另一个 div 中的组件。
为此,在树中我有 treestatelistener 实现
public void nodeSelected(Object node) {
log.debug("nodeSelected: " + node+ " class: " + node.getClass());
Component content = new Label("content");
content.replaceWith(new Label("content", "Hello World"));
}
}
}
我得到的只是消息:
“此方法只能在已经被调用的组件上调用 添加到其父级。”
ID 为“content”的标签在 init 时添加到页面中,因此它之前就存在。我做错了什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每次调用树节点侦听器时,您都会创建一个新的父组件,而不添加“内容”标签。
我建议尝试这样的事情 -
You are creating a new parent Component every time your treenode listener is called, without adding the 'content' label.
What I would suggest is to try something like this -
我总是在调用 Component.replaceWith() 时遇到问题。由于我使用 AJAX 执行此操作,因此我始终需要调用 target.add()。
我的解决方案现在是让类 MyTree 扩展 LinkTree 并在该类中重写 newNodeComponent()。
由于在我的应用程序中,一切都发生在 IndexPage.class 上,并且我只是替换组件,因此我向 IndexPage.Class 添加了一个方法 handleSelection()(extends BasePage 扩展网页)。在那里,我根据单击的节点对象决定如何替换 IndexPage 中的组件
我希望对此进行正确解释,否则:需要问题或评论!
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!