4 Replies Latest reply on Jan 21, 2009 7:42 AM by ilya_shaikovsky

    controlling rich:menu....no end in sight

      i'm trying to get control over the rich:menu (since....i don't know when)with a HasMap storing the state of the menu groups and the selectedChild Attribute for the active menu item. Over a method called after a specific user interaction the menu has to collapse the currently opened group and expand another group + setting a specific item as active. While the HashMap is called collapsing seems to work but the menu won't expand even though the HasMap contains the correct values. Any ideas?

        • 1. Re: controlling rich:menu....no end in sight
          nbelaevski

          Hello,

          This works well for me:

          <rich:panelMenu>
           <rich:panelMenuGroup expanded="#{true}" label="Group 1">
           <rich:panelMenuItem label="Item 1" />
           <rich:panelMenuItem label="Item 2" />
           </rich:panelMenuGroup>
           <rich:panelMenuGroup expanded="#{true}" label="Group 2">
           <rich:panelMenuItem label="Item 1" />
           <rich:panelMenuItem label="Item 2" />
           </rich:panelMenuGroup>
           <rich:panelMenuGroup expanded="#{false}" label="Group 3">
           <rich:panelMenuItem label="Item 1" />
           <rich:panelMenuItem label="Item 2" />
           </rich:panelMenuGroup>
           </rich:panelMenu>

          How do you reproduce the issue?

          • 2. Re: controlling rich:menu....no end in sight

            with rf 3.3.0 (btw. thanks a lot for that version!!) the menu groups behave as expected but the thing with the selected item still doesn't work. i create the menu dynamically and found out that neither

            menu.setSelectedChild("#{NavigationMenu.selectedChild}");

            nor
            menu.setValueExpression("selectedChild", createValueExpression("#{NavigationMenu.selectedChild}", String.class));

            seem to call/get/set the selectedChild value. here's the (simplified) code of the NavigationMenu bean holding the menu:

            // Creating the menu
            private void generateMenu ()
             {
             panelState = new HashMap<String, Boolean>();
             menu = new HtmlPanelMenu ();
             menu.setExpandSingle(true);
             menu.setId("mainMenu");
             menu.setMode("ajax");
             menu.setExpandMode("none");
             menu.setValueExpression("selectedChild", createValueExpression("#{NavigationMenu.selectedChild}", String.class));
             panelMenuGroup = generateSingleMenuGroup("header_01", render_header_01, "path1.jsp");
             generateSingleItem("item_01", render_item_01, "folder01/file01.jsp");
             menu.getChildren().add(panelMenuGroup);
            /* do same for all groups and items */
            }


            // Creates the panelGroup, menu kept simple in this case
            private HtmlPanelMenuGroup generateSingleMenuGroup (String labelName, boolean rendered, String path)
             {
             HtmlPanelMenuGroup tmpGroup = new HtmlPanelMenuGroup();
             tmpGroup.setLabel(rb.getString(labelName));
             tmpGroup.setRendered(rendered);
             tmpGroup.setId(labelName);
             tmpGroup.setName(labelName);
             tmpGroup.setValueExpression("value", createValueExpression("#{NavigationMenu.panelState['"+labelName+"']}",String.class));
             panelState.put(labelName, false);
             return tmpGroup;
             }


            // Creates the menuItems
            private void generateSingleItem(String labelName, boolean rendered, String path)
             {
             HtmlPanelMenuItem tmpPanelMenuItem = new HtmlPanelMenuItem();
             tmpPanelMenuItem.setReRender("ajaxArea");
             tmpPanelMenuItem.setIgnoreDupResponses(true);
             tmpPanelMenuItem.setLimitToList(false);
             tmpPanelMenuItem.setLabel(rb.getString(labelName));
             tmpPanelMenuItem.setId(labelName);
             tmpPanelMenuItem.setName(labelName);
             tmpPanelMenuItem.setRendered(rendered);
             UIParameter fParam = new UIParameter();
             fParam.setName(vh.getParamName());
             fParam.setValue(path);
             tmpPanelMenuItem.getChildren().add(fParam);
             tmpPanelMenuItem.setActionExpression(createActionExpression("#{ViewHandler.viewHandlerAction}"));
             panelMenuGroup.getChildren().add(tmpPanelMenuItem);
             }


            // Switches to a specific item
            public void switchToBackgroundprocesses(ActionEvent event)
             {
             //panelState = new HashMap<String, Boolean>();
             //THE GROUPS TO BE CLOSED
             this.panelState.put("header_01", false);
             this.panelState.put("header_02", false);
             /* and so on...*/
            
             // THE GROUPS TO BE OPENED
             this.panelState.put("header_03", true);
            
             // THE ITEM TO BE SHOWN IN ITALICS
             selectedChild = "item_04";
             }


            // Should create Creates the value expression, e.g. for the selectedChild
            private ValueExpression createValueExpression(String valueExpression, Class<?> cls)
             {
             FacesContext facesContext = FacesContext.getCurrentInstance();
             return facesContext.getApplication().getExpressionFactory().createValueExpression(
             facesContext.getELContext(), valueExpression, cls);
             }


            • 3. Re: controlling rich:menu....no end in sight

              selectedChild is called once at first load. so the value expression itself should be fine.

              • 4. Re: controlling rich:menu....no end in sight
                ilya_shaikovsky