初始化树时展开 Wickets TreeTable 节点
我对 wicket 很陌生,我正在尝试创建一个简单的 wicket 树来保存有关邮件列表的信息。该邮件列表与某封信相关。
- 邮件列表Dto 1
- 用户 1
- 用户 2
- MailingListDto 2
- 用户 3
- 用户 4
如果我们正在编辑一封现有信件,则与该信件相关的邮件列表将被提取到 mailingListCollection 中,并且应选择并展开树上的相应节点。由于某种原因,我似乎无法正常工作。
选定和展开的节点不会在 UI 中显示为选定或展开,但如果我以编程方式遍历选定的节点(例如在 onAfterRender()
中)并记录选定和展开的值,则节点将展开并选择。
tree = new TreeTable("treeTable", treeModel, treeColumns) { @Override public void onBeforeRender() { super.onBeforeRender(); if (!mailingListCollection.isEmpty()) { for (MailingListDto mailingList : mailingListCollection) { tree.getTreeState().expandNode(mailingList); tree.getTreeState().selectNode(mailingList, true); } } tree.updateTree(); } @Override protected void onAfterRender() { super.onAfterRender(); if (LOG.isDebugEnabled()) { LOG.debug("onAfterRender: " + tree.getTreeState().getSelectedNodes().size()); for (Object obj : tree.getTreeState().getSelectedNodes()) { LOG.debug(tree.getTreeState().isNodeSelected(obj) + " " + tree.getTreeState().isNodeExpanded(obj)); } } } }; tree.setRootLess(true); tree.getTreeState().setAllowSelectMultiple(true); add(tree);
I'm pretty new to wicket and I'm trying to create a simple wicket tree that holds information about mailinglists. This mailinglist is related to a certain letter.
- MailingListDto 1
- User 1
- User 2
- MailingListDto 2
- User 3
- User 4
If we are editing an existing letter, the mailinglists related to that letter are fetched into mailingListCollection
and the corresponding nodes on the tree should be selected and expanded. For some reason I don't seem to get this workin.
The selected and expanded nodes do not show as selected nor expanded in the UI, but if I go through the selected nodes programmatically for example in onAfterRender()
and log the selected and expanded values, the nodes are expanded and selected.
tree = new TreeTable("treeTable", treeModel, treeColumns) { @Override public void onBeforeRender() { super.onBeforeRender(); if (!mailingListCollection.isEmpty()) { for (MailingListDto mailingList : mailingListCollection) { tree.getTreeState().expandNode(mailingList); tree.getTreeState().selectNode(mailingList, true); } } tree.updateTree(); } @Override protected void onAfterRender() { super.onAfterRender(); if (LOG.isDebugEnabled()) { LOG.debug("onAfterRender: " + tree.getTreeState().getSelectedNodes().size()); for (Object obj : tree.getTreeState().getSelectedNodes()) { LOG.debug(tree.getTreeState().isNodeSelected(obj) + " " + tree.getTreeState().isNodeExpanded(obj)); } } } }; tree.setRootLess(true); tree.getTreeState().setAllowSelectMultiple(true); add(tree);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要仅展开树的根节点:
要还展开根节点的第一个子节点,请将以下行添加到前面的行:
请注意,您必须展开“目标”节点的所有父节点,否则屏幕上的目标由于父节点折叠,节点将被隐藏。
To expand only the root node of your tree:
To expand also the first child of the root node add the following line to the previous ones:
Note that you have to expand all parent nodes of the "target" node otherwise on the screen the target node will be hidden because of a collapsed parent.
wicket 1.5.10
wicket 6
看源代码。在类 FooExpansion.java 中有一个方法 ExpandAll()。
FooExpansion.java 用于私有类 FooExpansionModel.java 用于 AdvancedTreePage.java。
因此,在初始化树时(在 AdvancedTreePage.java 中),一个简单的解决方案可能是:
FooExansionModel model = new FooExpansionModell()
tree = createTree(provider, model);
((FooExpansion)model.getObject()).expandAll();
wicket 1.5.10
wicket 6
Look at source code. In class FooExpansion.java is a method expandAll().
FooExpansion.java is used in private class FooExpansionModel.java is used in AdvancedTreePage.java.
So a simple solution, when init your tree (in AdvancedTreePage.java), could be:
FooExansionModel model = new FooExpansionModell()
tree = createTree(provider, model);
((FooExpansion)model.getObject()).expandAll();