初始化树时展开 Wickets TreeTable 节点

发布于 2024-09-10 03:59:11 字数 1574 浏览 12 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦在深巷 2024-09-17 03:59:11

要仅展开树的根节点:

Object rootObj = myTree.getModelObject().getRoot();
myTree.getTreeState().expandNode(rootObj);

要还展开根节点的第一个子节点,请将以下行添加到前面的行:

myTree.getTreeState().expandNode(myTree.getModelObject().getChild(rootObj, 0));

请注意,您必须展开“目标”节点的所有父节点,否则屏幕上的目标由于父节点折叠,节点将被隐藏。

To expand only the root node of your tree:

Object rootObj = myTree.getModelObject().getRoot();
myTree.getTreeState().expandNode(rootObj);

To expand also the first child of the root node add the following line to the previous ones:

myTree.getTreeState().expandNode(myTree.getModelObject().getChild(rootObj, 0));

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.

一口甜 2024-09-17 03:59:11

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();

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文