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

    Dynamic ToolBar woes

    Kristoffer Carnmarker Newbie


      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)

       <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}"/>
      <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.setTarget(requestContextPath + "/restricted/manageUsers.jsf");
       HtmlOutputLink minst = new HtmlOutputLink();
       minst.setTarget(requestContextPath + "/restricted/manageInstitution.jsf");
       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?


        • 1. Re: Dynamic ToolBar woes
          Nick Belaevski Master


          "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
            Kristoffer Carnmarker Newbie

            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?



            • 3. Re: Dynamic ToolBar woes
              Kristoffer Carnmarker Newbie

              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.