cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with Menu Navigation

Former Member
0 Kudos

Hello!

I am very new to the subject of web dynpro programming, and i faced a problem while programming a menu navigation.

I have two views, located in a view Container- one is for my navigation (MenuBar), which should load dynamically different views in my "contentContainer", corresponding to the MenuActionItem Text, which is chosen in the Menu.

The different MenuActionItems have individual texts, but trigger the same event, on which my contentView listens.

How can I find out in wdDoModifyView(), which item has been chosen in the Menu? I think I have to put somehow the "text"-property of the menuActionItem in the parameter of the event? How can this be done?

Thanx in advance for your help!

Ilona Seifert

Accepted Solutions (1)

Accepted Solutions (1)

roberto_tagliento
Active Contributor
0 Kudos

You ust work with ViewSet and navigation link:

https://www.sdn.sap.com/irj/sdn/developerareas/webdynpro?rid=/library/uuid/49f2ea90-0201-0010-ce8e-d...

Look this tutorial

View Set 2 | 4 | 13 | 14

Plug, inbound, outbound 1 | 2 | 15 | 40

Answers (3)

Answers (3)

Former Member
0 Kudos

Ilona,

don't use wdDoModifyView() at all for this. Either create different actions for the menu items or add a constant event parameter to identify the caller of the action.

In newer IDE versions, you can do this with the parameter mapping editor, in older versions, you have to write some code.

Using different actions is probably easiest here (menu action items even inherit text and icon from the assigned action).

Armin

Former Member
0 Kudos

Hi!

Thank you very much for your answers!

Nevertheless I have to generate somehow a dynamic Menu, which I e.g. construct by the given elements of an xml file, without designing a specific action and inbound/outbound plug for every menu entry.

Do you have more helpful ideas?

Kind Regards

Ilona

Former Member
0 Kudos

Ilona,

if you need something more dynamic, you can go the following route.

You need an event handler method in the view controller. This must be created at designtime.

You can also use a common action "MenuItemSelected" with a parameter "itemID" for all menu items. In that case, you can use a constant event parameter for dispatching which item triggered the action.

Example code:


String[] items = {"DoThis", "DoThat"};

void wdDoModifyView(...)
{
  if (<menu must be recreated>)
  {
    IWDMenu menu = (IWDMenu) view.getElement("menuID");
    menu.destroyAllItems();
    for (int ix = 0; ix < items.length; ++ix)
    {
      IWDMenuActionItem menuItem = (IWDMenuActionItem) view.createElement(IWDMenuActionItem.class, null);
      menu.addItem(menuItem);
      menuItem.setText(items[ix]);
      menuItem.setOnAction(wdThis.wdGetOnMenuItemSelectedAction());
      menuItem.mappingOfOnAction().setString
      (
        "itemID", /* name of action parameter */
        items[ix] /* text of menu item, better use an ID */
      )
    } 
  }
}

void wdOnMenuItemSelected(..., String itemID)
{
  if ("DoThis".equals(itemID))
  {
    /* do this */
  }
  else if ("DoThat".equals(itemID))
  {
    /* do that */
  }
}

Armin

Former Member
0 Kudos

Hello Armin!

Thanks a lot for your answer! This is exactly what I need. My last problem now is, how to set the different event parameters, according to the menu item which has been clicked. In your case it is the Parameter "itemID", how do I get it, according to the different items?

I have one event in the Controller Interface, which I call by the following source code in my "menu view":

public void onActiongoToContainer(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, java.lang.String name ) {

//@@begin onActiongoToContainer(ServerEvent) wdThis.wdGetTrwInterfaceController().wdFireEventNavigationEvent(name);

//@@end

}

Now I need to set the parameter "name", according to the "text"-Attribute of my MenuActionItem or the ID. How do I get it?

Kind Regards

Ilona

Former Member
0 Kudos

Ilona,

Armin already provided an answer, just apply it to your variables/method names:

instead of


      menuItem.setOnAction(wdThis.wdGetOnMenuItemSelectedAction());
      menuItem.mappingOfOnAction().setString
      (
        "itemID", /* name of action parameter */
        items[ix] /* text of menu item, better use an ID */
      )

use


      menuItem.setOnAction(wdThis.wdGetOnActiongoToContainer());
      menuItem.mappingOfOnAction().setString
      (
        "name", /* name of action parameter */
        items[ix] /* text of menu item, better use an ID */
      )

I just replaced action handler name and name of parameter.

So your action handler onActiongoToContainer will get parameter "name" as items[idx] automatically.

VS

roberto_tagliento
Active Contributor
0 Kudos

For each Menu Item you must have specific Action and OutBoundPlug.

Former Member
0 Kudos

Hi,

The onAction event of MenuActionItem does not send back any parameters from the client side. So it would not be possible to find out which actionItem has been selected by the user.

The best thing in your case would be to have different event handlers for different actions.

Regards,

Satyajit.