collapse in primefaces(version 7.0) dynamic menu by default doesn't work

Viewed 122

I implemented a dynamic menu. Its works with the click of a submenu. This menu should be collapsed by default and should expand only by the click of the submenu. But the submenus are expanded by default(Expected behavior: collapse because of code firstSubmenu.setExpanded(false)). Can someone help me?

here the code:

<p:menu toggleable="true" model="#{menuBean.model}"> </p:menu>

Code in bean:

    MenuModel model = new DefaultMenuModel();       
    List<ProductType> parentCategories =  getParentCategories();
    for (ProductType parentCategorie : parentCategories) {
        DefaultSubMenu firstSubmenu = new DefaultSubMenu(parentCategorie.getTypeName());  
        firstSubmenu.setExpanded(false);
        
        List<ProductType> childProductTypes = parentCategorie.getChildProductTypes();
        for (ProductType childCategorie: childProductTypes) {
            DefaultMenuItem item = new DefaultMenuItem(childCategorie.getTypeName());  
            item.setUrl("http://www.anyurl.org");  
            item.setIcon("ui-icon-home");          
            firstSubmenu.addElement(item);              
        }
        model.addElement(firstSubmenu);         
    }
0 Answers
Related