开发者

Expanding Wickets TreeTable nodes when initializing a tree

开发者 https://www.devze.com 2023-01-07 17:32 出处:网络
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.

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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消