You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by Apache Wiki <wi...@apache.org> on 2005/09/22 13:08:29 UTC

[Myfaces Wiki] Update of "Dynamic Menus with JSCookMenu" by BrunoAranda

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Myfaces Wiki" for change notification.

The following page has been changed by BrunoAranda:
http://wiki.apache.org/myfaces/Dynamic_Menus_with_JSCookMenu

New page:
Many people ask in the user list how to create a !JsCookMenu dynamically. This is the way:

1. Create a backing bean (in this example, named 'dynMenu') with the code to generate a !NavigationMenuItem[], like this:

{{{

import org.apache.myfaces.custom.navmenu.NavigationMenuItem;

public class DynamicMenuTest {

    private NavigationMenuItem[] navItems;

    public DynamicMenuTest() {
        // children for item 2
        NavigationMenuItem[] subItems = new NavigationMenuItem[2];
        subItems[0] = new NavigationMenuItem("Subitem 2_1 Label","action2_1", "iconUrl", false);
        subItems[1] = new NavigationMenuItem("Subitem 2_2 Label","action2_2", "iconUrl", false);
        
        // item 2
        NavigationMenuItem itemWithChildren = new NavigationMenuItem("Item 2 Label", "action2", "iconUrl", false);
        itemWithChildren.setNavigationMenuItems(subItems);
        
        // root items
        navItems = new NavigationMenuItem[3];
        navItems[0] = new NavigationMenuItem("Item 1 Label","action1", "iconUrl", false);
        navItems[1] = itemWithChildren;
        navItems[2] = new NavigationMenuItem("Item 3 Label","action3", "iconUrl", false);
    }
    
    public NavigationMenuItem[] getNavItems() {
        return navItems;
    }

    public void setNavItems(NavigationMenuItem[] navItems) {
        this.navItems = navItems;
    }

}

}}}

2. Then, in your jsp use this code to call to the backing bean and to the generated menu:

{{{

   <x:jscookMenu layout="hbr" theme="ThemeOffice">
                <%/* Availaible jscookMenu themes: ThemeIE, ThemeMiniBlack,ThemeOffice, ThemePanel
             Availaible jscookMenu layout: hbr, hbl, hur, hul, vbr,vbl, vur, vul
             respect to Heng Yuan http://www.cs.ucla.edu/~heng/JSCookMenu
        */%>
                <x:navigationMenuItems value="#{dynMenu.navItems}" />
   </x:jscookMenu>

}}}