How to use rich:treeNodesAdaptor programmatically?
grundor Apr 30, 2008 4:07 PMHello,
I am trying to programmatically create a rich:tree from a model stored in the database. The tree is nested within a rich:panelMenuGroup. The panelMenu itself is dynamically created.
Here is the snippet of xhtml page source that shows the panelMenu binding:
<h:form id="navform"> <rich:panelMenu id="navMenu" binding="#{navigationAction.navMenu}"> </h:form>
Here is the getNavMenu implementation and code where the tree creation is attempted in my Seam component:
public HtmlPanelMenu getNavMenu() { if (navMenu != null) return navMenu; return buildNavMenu(); } private HtmlPanelMenu buildNavMenu() { List<Menutab> menutabs = sportHome.getInstance().getMenutabs(); navMenu = new HtmlPanelMenu(); navMenu.setExpandSingle(true); for (Menutab tab : menutabs) { HtmlPanelMenuGroup group = new HtmlPanelMenuGroup(); String label = tab.getMenutabCaption(); group.setLabel(label); String name = "navgrp_" + tab.getMenutabId(); group.setName(name); // Add pre-defined items if (tab.getMenutabType() == MenutabType.MENUTAB_TEAMS) { addTeamTree(group, tab.getSport().getSeasons()); } navMenu.getChildren().add(group); } return navMenu; } private void addTeamTree(HtmlPanelMenuGroup parentGroup, List<Season> seasons) { HtmlTree teamTree = new HtmlTree(); teamTree.setSwitchType("client"); HtmlTreeNodesAdaptor seasonAdaptor = new HtmlTreeNodesAdaptor(); seasonAdaptor.setNodes(seasons); seasonAdaptor.setVar("_season"); HtmlTreeNode seasonNode = new HtmlTreeNode(); seasonNode.setData("#{_season.seasonId}"); seasonNode.setIcon("img/season.png"); seasonNode.setIconLeaf("img/season.png"); HtmlOutputText text = new HtmlOutputText(); text.setValue("#{_season.seasonName}"); seasonNode.getChildren().add(text); teamTree.getChildren().add(seasonNode); parentGroup.getChildren().add(teamTree); }
So basically I am dynamically creating a MenuPanel control, and within one of the MenuPanelGroups I am attempting to create a tree control using HtmlTreeNodesAdaptor.
The panelmenu is displaying just fine, but the tree control does not display using the above code. Can anyone comment on whether I am on the right track? Is it valid to use HtmlTreeNodesAdaptor in this way?
Regards,
Mark