cancel
Showing results for 
Search instead for 
Did you mean: 

How to create Menu Dynamically

Former Member
0 Kudos

Dear Experts,

I have a requirement in which I have to create the menu dynamically,

these menu's I am getting from a R/3 table,

and the submenus also i am getting from R/3 table

And the sub menus I have make the type of menuAction.

Please suggest

Regards

Upendra Agrawal

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

First we must clarify what kind of menus we are talking about. Are we talking about menus in a MenuBar, about client-side, static menus (available since 7.0) or about server-side context menus (available since release 7.1).

Armin

Former Member
0 Kudos

Dear Armin,

I am talking about the menuBar, in it I have to create the menuItems depending upon the no. of enteries and their text which I am recieving from the RFC,

The menuBar will contain about 30 menuItems and each menuItem have about 30 menuActionItem.

creating them statically is a huge task and the no, of menuItems will depend on the RFC table, I have not worked on dynamically creating UI elements so request you to please suggest.

Warm Regards,

Upendra Agrawal

Former Member
0 Kudos

30 menus with 30 entries each? That's a litte bit too much for using menubars and menus. Maybe another representation would be more usable. But anyway...

First you need a suitable context structure to store the menus, submenus(?), items etc.

It might be useful to create such a structure in the view context and implement a supply function that fills the nodes from the backend data.

Example:


Context
+ rebuildMenus (boolean)
+ Menus (node, c=0:n)
   + id (string)
   + title (string)
   + MenuItems (node, c=0:n, singleton=false)
      + id (string)
      + text (string)
      + icon (string)

Create a MenuBar UI element "MenuBar" at design-time and add it to the view layout. Create an action "MenuItemSelected" with parameters "menuID" and "itemID" (string). This action will be used for all items, the parameters allow to identify which item in which menu triggered the action.

In the action handler that calls into the backend, set "rebuildMenus" to true.


wdDoModifyView(...)
{
  if ( wdContext.currentContextElement().getRebuildMenus() )
  {
    IWDMenuBar menuBar = (IWDMenuBar) view.getElement("MenuBar");
    for (int i = 0; i < wdContext.nodeMenus().size(); ++i)
    {
      IMenusElement menuDesc = wdContext.nodeMenus().getMenusElementAt(i);
      addMenu(wdThis, wdContext, menuBar, menuDesc);
    }
    wdContext.currentContextElement().setRebuildMenus(false);
  }
}

private static void addMenu(... wdThis, ... wdContext, IWDMenuBar menuBar, IMenusElement menuDesc)
{
  IWDMenu menu = (IWDMenu) menuBar.getView().createElement(IWDMenu.class, menuDesc.getId());
  menu.setTitle( menuDesc.getTitle() );
  menuBar.addMenu(menu);
  for (int i = 0; i < menuDesc.nodeMenuItems().size(); ++i)
  {
    IMenuItemsElement itemDesc = menuDesc.nodeMenuItems().getMenuItemsElementAt(i);
    IWDMenuActionItem item = (IWDMenuActionItem) menu.getView().createElement(IWDMenuActionItem.class, itemDesc.getId());
    item.setOnAction( wdThis.wdGetMenuItemSelectedAction() );
    item.mappingOfOnAction().addParameter("menuID", menu.getId());
    item.mappingOfOnAction().addParameter("itemID", item.getId());
    menu.addItem(item);
  } 
}

Checkboxes, radio buttons and submenus are left as an exercise for the reader

Armin

Answers (2)

Answers (2)

Former Member
0 Kudos

Dear Armin,

Thanks, a lot .

Upendra

Former Member
0 Kudos