Generate Vaadin menu on the fly

Hi everybody,

When I use the Vaadin menubar (
) everything works fine: my server side code generates a menubar once, containing all the menu items and sub menu items.

However in my application the sub menus aren’t fixed, but should be generated at the moment the user clicks the corresponding menu item. For example when a user selects the ‘Beverages’ menu item, I want to execute some server side code to generate a submenu containing ‘Hot’ and ‘Cold’ sub menu items. Other sub menu items could be added, based on the current circumstances.

I wrote following code snippet to test this:

// A top-level menu item that opens a submenu
final MenuItem drinks = barmenu.addItem(“Beverages”, null, null);

    // Define a common menu command
    drinks.setCommand(new MenuBar.Command() {
        public void [b]

[/b](MenuItem selectedItem) {

            // Add two submenu items when the user clicks the 'beverages' menu item
            MenuItem hots = drinks.addItem("Hot", null, null);
            MenuItem colds = drinks.addItem("Cold", null, null);
            // barmenu.markAsDirty();


However nothing happens on the client, only the ‘Beverages’ menu item is visible. Even the markAsDirty() doesn’t show the ‘Hot’ and ‘Cold’ sub menu items. In the client, only the following html is available:


It seems like the menubar hasn’t been designed for this purpose, since it couldn’t determine in advance whether a menu item has a submenu (e.g. to show the sub menu indicator ►). I also couldn’t find any addon that solves my issue.

Hopefully, there is a brilliant mind on this blue planet that knows a workaround for my problem :wink:

Thanks in advance,
Bart Butenaers