7 Replies Latest reply on Jan 22, 2010 6:53 AM by dushmanlk

    <rich:dropDownMenu>

    dushmanlk

      I use richfaces with facelets. i created a menu bar using <rich:dropDownMenu> bases on a values stored in a database in a seperate xhtml file.

      I set submit mode of 'ajax' and first time the menu gets rendered corrcetly.

      but when i load a new page in the body area clicking the menu item, all menue items gets dissapered. Only the parent menu is visible

      when submit mode of menuitems were set to 'server', this doesn't happens. i can see all parents and childs.

       

      can someone shed some light on this?

       

      thanks in advance,

      dushmanlk

        • 1. Re: <rich:dropDownMenu>
          ilya_shaikovsky
          please show code snippets.
          • 2. Re: <rich:dropDownMenu>
            dushmanlk

            in the menu.xhtml

            --------------------------------

             

             

            <rich:toolBar>

             

            <c:forEach items="#{menuItems.menuBar}" var="menu">

             

            <rich:dropDownMenu binding="#{menu}">

             

            </rich:dropDownMenu>

             

            </c:forEach>

             

            </rich:toolBar>

             

             

            in the faces config

            -------------------------------------

             

             

            <managed-bean>

             

            <managed-bean-name>menuItems</managed-bean-name>

             

            <managed-bean-class>com.dushman.web.menu.backing.MenuItemBean</managed-bean-class>

             

            <managed-bean-scope>session</managed-bean-scope>

             

            </managed-bean>

             

             

            in the MenuItemBean.java

            -----------------------------------------------

            private List menuList;

             

             

            public List getMenuBar() {

             

            if(menuList == null){

             

            menuList = getMenuComponent();

            }

             

            return menuList;

             

            }

             

             

             

            @SuppressWarnings

             

            ("unchecked")

             

            public List<UIComponent> getMenuComponent() {

             

            GrantedAuthority[] auth = SecurityContextHolder.getContext().getAuthentication().getAuthorities();

            ArrayList<String> buf =

            new ArrayList<String>();

             

            for (int i = 0; i < auth.length; i++) {

            buf.add(auth[i].getAuthority());

            }

            MenuItemDAO menuItem = (MenuItemDAO) ServiceFinder.findBean(

            "menuItemDao");

            List <MenuItem> list = menuItem.getMenuItemByRoles(buf);

            List<UIComponent> menuList =

            new ArrayList<UIComponent>();

            FacesContext ctx = FacesContext.getCurrentInstance();

            Application app = ctx.getApplication();

             

             

            for (Object menu : list) {

             

            HtmlDropDownMenu parent = (HtmlDropDownMenu) app.createComponent(HtmlDropDownMenu.

            COMPONENT_TYPE);

            parent.setValue(((MenuItem) menu).getItemName());

            parent.setId(((MenuItem) menu).getUiId());

            buildChildMenuItem(parent, ((MenuItem) menu).getChildMenus(), ctx);

            menuList.add(parent);

            }

             

            return menuList;

            }

             

             

             

            private UIComponent buildChildMenuItem(UIComponent parent, Set<MenuItem> childs,

            FacesContext context) {

             

             

            for (Iterator<MenuItem> iterator = childs.iterator(); iterator.hasNext();) {

            MenuItem menuItem = (MenuItem) iterator.next();

             

             

            if (menuItem.getChildMenus().size() == 0) {

            HtmlMenuItem item = (HtmlMenuItem) context.getApplication().createComponent(HtmlMenuItem.

            COMPONENT_TYPE);

            item.setValue(menuItem.getItemName());

            item.setId(menuItem.getUiId());

            item.setSubmitMode(

            "ajax");

            MethodExpression actionExpression = context.getApplication().getExpressionFactory()

            .createMethodExpression(context.getELContext(),menuItem.getUri(), String.

            class, new Class[]{});

            item.setActionExpression(actionExpression);

             

            // String onSelect = "open(this,'" +

             

            // menuItem.getItemName().toString() + "')";

             

            // item.setOnselect(onSelect);

             

            parent.getChildren().add(item);

            }

            else

             

            {

            HtmlMenuGroup itemHasChilds = (HtmlMenuGroup) context.getApplication().createComponent(HtmlMenuGroup.

            COMPONENT_TYPE);

            itemHasChilds.setValue(menuItem.getItemName());

            itemHasChilds.setId(menuItem.getUiId());

            parent.getChildren().add(itemHasChilds);

            buildChildMenuItem(itemHasChilds, menuItem.getChildMenus(),context);

             

            }

            }

             

             

            return parent;

             

            }

             

            template.xhtml

            ---------------------------

             

             

            <body>

             

             

            <div id="page">

             

             

             

            <div id="header"><ui:insert name="header">Header</ui:insert></div>

             

             

             

            <div id="menu"><ui:include src="/WEB-INF/includes/menu.xhtml" /></div>

             

             

             

            <div id="navigation"><ui:insert name="navigation">Navigation</ui:insert></div>

             

             

             

            <div id="content"><ui:insert name="content">Content</ui:insert></div>

             

             

            <div id="footer"><ui:include src="/WEB-INF/includes/footer.xhtml" /></div>

             

            </div>

             

             

            thank you showning interest in my question

             

            dushmanlk

             

             

             

            • 3. Re: <rich:dropDownMenu>
              dushmanlk

              But when i save the page to the file system and view it again. child menuescan be seen.

              I'm using firefox browser

              • 4. Re: <rich:dropDownMenu>
                ilya_shaikovsky
                component bindings should not be session scoped.
                • 5. Re: <rich:dropDownMenu>
                  dushmanlk

                  I changed it to request scope. still the problem exists.

                   

                   

                  Attached the screen shots before and after submit.

                  before submit, all child items are poulated.

                  after submit even i move cursor over the file menu child elements are not dispalyed.

                  but when i changed the submit mode to 'server' this works.

                   

                  I used <ui:debug> and inspected view root. there is no diffence in both view roots

                  with refernce to menu components.

                   

                  Any help very much appriciared.

                   

                  Dushman.

                  • 6. Re: <rich:dropDownMenu>
                    nbelaevski

                    Hi,

                     

                    Check if there are any errors in browser log & a4j:log component.

                    • 7. Re: <rich:dropDownMenu>
                      dushmanlk

                      Hi, Nick

                      I did check a4j:log

                      but its empty