cancel
Showing results for 
Search instead for 
Did you mean: 

Menu action Item UI element

Former Member
0 Kudos

hi,

I have few menuactionitem UI elements in a menu UI elem. I have bound the same Action to all the menuactionitem's OnAction property. I have created a parameter in this action. This parameter is to identify at runtime which menuactionitem has been clicked.

When I click on the menuaction item at runtime, it throws ClassCastException.

Does anyone has any idea wht is the problem ?

The type of parameter that I am using with the action is IWDMenuActionItem. Do I need to change the type of parameter. If yes, then wht shud be its type. The purpose is to get handle of the menuactionitem that has been clicked by the user.

Any help is greatly appreciated !

Thankyou !

Edited by: codenoob on Mar 13, 2009 11:35 AM

Edited by: codenoob on Mar 13, 2009 11:36 AM

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member185086
Active Contributor
0 Kudos

Hi

What is the parameter for this?

MenuActionItem require parameter of type nodeElement (IWDNodeElement) so pass this error will resolve.

Best Regards

Satish Kumar

Former Member
0 Kudos

hi,

thankyou satish for fast reply. I shall change the type of parameter to IWDNodeElement and try.

I am not able to make any change in the code due to some other process running in NWDS.

can you tell me how do we come to know that what shud be the type of parameter for various UI elements ?

Like if the action is bound to a button UI elm and I want to pass a parameter to identify which button is clicked then wht shud be type of parameter in the associated action ? similarly for other UI elem on which action can be applied like link to action, link to URL etc..

Regards,

Codenoob.

former_member185086
Active Contributor
0 Kudos

Hi

Select that UI element right Click and select parameter mapping It display the action with its parameter .

Same thing we have to provide it to access.

Dont be confuse here that all context menu require nodeElement u will come to know the difference once u see it.

Best Regards

Satish Kumar

Former Member
0 Kudos

hi,

but satish, if the type of parameter is IWDNodeElement for menuactionitem, how will I be able to get the ID of menuactionitem clicked by the user. If I am not able to get its ID, I can not identify it.

former_member185086
Active Contributor
0 Kudos

Hi

Sorry I forget to mention, nodeElement it could be string also. in simple words It will the id form different menus.

Best Regards

Satish Kumar

Former Member
0 Kudos

satish,

I tried using String also, but the parameter of string type does not carry the ID of the menuactionitem.

It simply is null string.

When the type of parameter is String, In parameter mapping statement I am writing the following...

just have a look ..is it correct ?

IWDMenuActionItem mnuitem = (IWDMenuActionItem) view.getElement("mnu_Material");

mnuitem.mappingOfOnAction().addSourceMapping("nodeElement","attribute");

where attribute is the name of parameter.

Shud I use something else inplace of "nodeElement" ; the first parameter of addSourceMapping() method ?

Edited by: codenoob on Mar 13, 2009 12:28 PM

Former Member
0 Kudos

Hi,

Following is a way to use it



 public void wdDoModifyView(com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
  {
    //@@begin wdDoModifyView

	  if (firstTime)
	  {
		  for (int index = 0;index < 10;index ++)
		  {
			  IWDMenuActionItem menuItem = (IWDMenuActionItem)view.createElement(IWDMenuActionItem.class);
			  menuItem.setOnAction(wdThis.wdGetMyActionAction()); // This action "MyAction" Should be existing
			  menuItem.mappingOfOnAction().setInt("Index", index);
		  }
	  }
    //@@end
  }

 //@@end
  public void onActionMyAction(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, int Index )
  {
    //@@begin onActionMyAction(ServerEvent)
	  
	  //Use index to find the respective button pressed
	  
    //@@end
  }

Regards

Ayyapparaj

Former Member
0 Kudos

hi ,

Thanks for your reply. But mappingofOnAction() method does not have set method in it.

so I can not set indexes to the same parameter for diffrerent menuactionitmems.

Former Member
0 Kudos

Hi,

If setMethods are not their use addParameter.

Regards

Ayyapparaj

former_member185086
Active Contributor
0 Kudos

Hi

Do you want this on runtime or want to define at design time.

Use this [thread|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/061f0ca3-0c01-0010-67a6-ecc32193442f] for more input

BR

Satish Kumar

Former Member
0 Kudos

I want the ID of element at runtime. I have declared action and its parameter at design time.

I have bound this action to all the menuactionitems in the menu.

Now when I click on menuaction item, the control goes to eventhandellar of the action defined and bound to this menuactionitem. In this eventhandellar, I want to get the ID of menuaction item ...that has been clicked by the user .

Former Member
0 Kudos

Hi,

Use as follows while

//Based on the above post

menuItem.mappingOfOnAction().addParameter("Id", menuItem.getId());

Regards

Ayyapparaj

Former Member
0 Kudos

Add an action parameter "menuItemId" of type "string" to the action (and its event handler method).

Define a parameter mapping that fills the "menuItemId" for each menu item. This can either be done at design-time using the parameter mapping editor ("fixed parameter") or using code like this:


wdDoModifyView(...)
{
  if (firstTime)
  {
    IWDMenu menu = (IWDMenu) view.getElement("menu_id");
    for (Iterator items = menu.iterateItems(); items.hasNext(); )
    {
      IWDMenuItem item = (IWDMenuItem) items.next();
      if (item instanceof IWDMenuActionItem)
      {
        ((IWDMenuActionItem) item).mappingOfOnAction().addParameter("menuItemId", item.getId());
        /* in newer releases use setString(...) */
      }
    }
  }
}

Armin