3 Replies Latest reply on Apr 9, 2007 2:57 AM by krica

    Dynamic ToolBar woes

    krica

      Hi,

      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

        • 1. Re: Dynamic ToolBar woes
          nbelaevski

          Kris,

          "rendered" is the right attribute for preventing user interaction with the component on some conditions.

          I can see that "subMenu" component is outside the form. To re-render components that are in naming container other than the component establishing re-rendering, you should use absolute id in reRender attribute, eg. ":subMenu". Or you can just try to put "subMenu" component under h:form tag.

          • 2. Re: Dynamic ToolBar woes
            krica

            Hi Nick,

            Thanks for the response.

            You know how it is when you are trying different things out in order to find a workaround. The "subMenu" component was originally inside the form element. Just in case I misremembered, I tried it again and sure enough, it made no difference.

            Any other ideas?

            Thanks!

            /Kris

            • 3. Re: Dynamic ToolBar woes
              krica

              I just tested with the following changes:

              -Put and explicit id on the form element and changed to reRender="menuBarForm:subMenu". No help.

              -Changed from a4j:commandLink to regular h:commandLink, action="#{menuBar.selectedSubMenu}". Both with an f:param with the value of the clicked item and also using Seam's EL extension (i.e. action="#{menuBar.selectedSubMenu('admin'}". This did change the behaviour. Now the subMenu toolbar appears after clicking on the menu item, but it is an empty toolbar.