Dynamic ToolBar woes
krica Apr 8, 2007 9:37 AMHi,
While we are all waiting for the drop down menu component, I thought I'd use two ToolBar components to get the job done. I have a top toolbar and a second, dynamic toolbar right below it. This dynamic toolbar changes depending on the item clicked on in the top toolbar.
The toolbars are defined in my file menu.xhtml (which is included in my template.xhtml)
<h:form> <rich:toolBar height="26" itemSeparator="none"> <rich:toolBarGroup itemSeparator="none"> <a4j:commandLink value="Admin" reRender="subMenu" rendered="#{s:hasRole('Admin')}"> <a4j:actionparam name="sm" value="admin" assignTo="#{menuBar.selectedSubMenu}"/> </a4j:commandLink> ... </rich:toolBarGroup> </rich:toolBar> </h:form> <rich:toolBar id="subMenu" height="30" itemSeparator="none" binding="#{activeSubMenu}" rendered="#{not empty activeSubMenu.children}"/>
As you see, the "subMenu" toolbar is bound to a component "activeSubMenu", which is created and updated by the component "menuBar".
First question: rendered="#{not empty activeSubMenu.children} is the only way I found to hide the subMenu in the case there IS no subMenu. I tried all sorts of expressions there, like the obvious #{activeSubMenu != null}. What is the best way to enable/disable this toolbar?
The top toolbar calls (via a4j) the menuBar component's selectedSubMenu method:
public void setSelectedSubMenu(String selectedSubMenu) { this.selectedSubMenu = selectedSubMenu; activeSubMenu = subMenus.get(selectedSubMenu); }
subMenus is simply a Map of possible subMenu components, e.g. defined like this:
HtmlToolBar adminTb = new HtmlToolBar(); HtmlOutputLink mu = new HtmlOutputLink(); mu.setValue(messages.get("label_menuBar_ManageUsers")); mu.setTarget(requestContextPath + "/restricted/manageUsers.jsf"); adminTb.getChildren().add(mu); HtmlOutputLink minst = new HtmlOutputLink(); minst.setValue(messages.get("label_menuBar_ManageInst")); minst.setTarget(requestContextPath + "/restricted/manageInstitution.jsf"); adminTb.getChildren().add(minst); subMenus.put("admin", adminTb);
The problem is that the subMenu never gets updated in the view. I see setSelectedSubMenu get called, and the activeSubMenu gets returned correctly. Via Seam's debug page I can also see that the component "activeSubMenu" is alive and well in the Session context, with its two children.
Originally I had activeSubMenu as a property of menuBar, and I saw that the getter for it was called and the correct toolbar was returned.
Please, what do I need to do?
Thanks,
Kris