Saturday 30 January 2010

smartGWT MenuBar - this.menus is undefined error

When you are attempting to add a smartGWT MenuBar to your screen, usually at system startup. If you get an error like this:

  com.google.gwt.core.client.JavaScriptException: (TypeError): this.menus is undefined

then check that you have used setMenus in when you first instantiate the menu bar. For example:
            MenuBar menuBar = new MenuBar();
           
            menuBar.setMenus(myFirstMenu,mySecondMenu);
           
            menuBar.setVisible(true);
            menuBar.setKeepInParentRect(false);

            RootPanel.get("menuPanel").add(menuBar);       


It is possible to use the add functions to add members and menus, but the underlying JavaScript needs a setMenu call to have the array that stores the menus initialised.

smartGWT MenuBar - setMenus and addMenus undefined

If you are using smartGWT and you are attempting to use the smartGWT MenuBar class, but keep getting "setMenu undefined" or "addMenu undefined" errors, then check your imports.

Google have a MenuBar in GWT as well. The package is com.google.gwt.user.client.ui.MenuBar.

The correct package to be using is  com.smartgwt.client.widgets.menu.MenuBar.