cancel
Showing results for 
Search instead for 
Did you mean: 

dropdownbykey: how to implement onSelect action

Former Member
0 Kudos

I was trying to bind an action with onSelect event of dropdownbykey, but I couldn't get figure out how to get selected value in the action defined.

I was trying to access the selected key by using following code but it prints nothing.

wdEvent.getString("key");

Any idea what I have been doing wrong.

regards,

Jawed Ali

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Use

wdContext.current<Your Node>Element().get<Your Attribute>()

Ex:

lets say the node name is orders and the attribute ordertype is bound to the drop down by key the following code will return you the selected.

wdContext.currentOrdersElement().getOrderType()

Regards

Ayyapparaj

Former Member
0 Kudos

I have value Node Line Item with elements, productid, price and quantity.

lineitem
   |----productId
   |----price
   |----qty

as I have multiple line items so I have mutiple dropdown boxes when users select a product on any row from the dropdown how I am gonna find which was the currentnodeElement() for line item.

Former Member
0 Kudos

Hi,

Create a parameter of type string to onSelect action, lets say "key"

Go to the outline view

select the drop down by key right click and select parameter mapping.

from the right side drag the "key" previously created to the left side "key"

access this parameter from code this will return you the selected key.

Ex your method signature will look as follows



public void onActionTest(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, java.lang.String key )
  {
    //@@begin onActionTt(ServerEvent)
           
        wdComponentAPI.getMessageManager().reportSuccess(key);

    //@@end
  }

Regards

Ayyapparaj

Former Member
0 Kudos

Map the (implicit) event parameter named "nodeElement" to a corresponding action parameter "row" of type "ILineitem" (or however the node name is). You can do this either with the parameter mapping editor (Outline -> right-click -> "Parameter Mapping") or, if this is not available in your version, by code in wdDoModifyView():


if (firstTime)
{
  IWDDropDownByKey ddList = (IWDDropDownByKey) view.getElement("ddListID");
  ddList.mappingOfOnSelect().addSourceMapping("nodeElement", "row");
}

In the action handler, you can get the selected key for the given table row by


String selectedID = row.getProductId();

Armin

Former Member
0 Kudos

Thanks Armin and Ayyapparaj KV, I have solved my problem by integrating your suggestions:

I first added following lines in ModifyView method:


  public static void wdDoModifyView(IPrivateDynamicView wdThis, IPrivateDynamicView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
  {
    //@@begin wdDoModifyView
	if (firstTime)
	{
	  IWDDropDownByKey ddList = (IWDDropDownByKey) view.getElement("DropDownByKey");
	  ddList.mappingOfOnSelect().addSourceMapping("nodeElement", "key");
	}
    //@@end
  }

I have added a parameter "key" of type ILineItemElement to ProductSelect action and mapped this action to Dropdown's onSelect event.

  public void onActionProductSelect(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, com.dynamic.ui.wdp.IPrivateDynamicView.ILineItemElement key )
  {
    //@@begin onActionProductSelect(ServerEvent)
    wdContext.currentContextElement().setTestValue(key.getProductId());	
    //@@end
  }

Thank you,

Jawed Ali

Former Member
0 Kudos

Naming this parameter "key" is misleading because it does not correspond to the explicit parameter "key" but to the implicit parameter "nodeElement" which determines the table row.

Armin

Former Member
0 Kudos

Hi,

The currentContextElement of the node will give you the selected value.

Regards,

Sudhir