views:

106

answers:

0

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