cancel
Showing results for 
Search instead for 
Did you mean: 

get the selected key of a dynamic dropdownbykey ui element

yasu_ramaiah
Explorer
0 Kudos

Hello

I ve craeted a dynamic DropDownByKey UI element and I bound it to a context attribute. The dropdown works fine with dynamic values. Now I want to get the user selected key of the dropdownbykey UI element.

Any help will be apprecaite very much and rewarded as well

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

https://media.sdn.sap.com/javadocs/NW04/SP12/webdynpro/com/sap/tc/webdynpro/clientserver/uielib/stan...

Bind property "selectedKey" to a context attribute and get the selected key from there.

Armin

Answers (1)

Answers (1)

yasu_ramaiah
Explorer
0 Kudos

Hello Armin,

Thanks for your response. Your api link certainly helped me out. I used the static reference of the dropdown UIelement. Is there any other api through which I can access the UIelements of the view directly.

Will be looking forward for your response.

Thanks

Former Member
0 Kudos

Never store references to UI elements in static view member variables, never.

Only place to access view elements is in method wdDoModifyView() which gets the view as a parameter.

Every manipulation of view element properties should be done via data binding to view context.

Armin

yasu_ramaiah
Explorer
0 Kudos

Hello Armin,

Thanks for your response again. Right now in my project I am not using the staticly referenced UI element, I have created the DDK(Say ID=DDKUI) and did bind it to a value attribute(ShipTo is created and is of type simpletype) at design time but populating the value attrib node dynamically. Now I can access the user selected key by calling wdContext().currentContextElement().getShipTO().

This is how I have been doing it from the past few years.

Suppose I ve created the DDK & bound it to a value attribute dynamically. Two ways of getting the user selected value is

1. DDKObj.getSelectedKey() according to WD standards I would only be able do it in wdModifyView()

2. wdContext.currentContextElement().getAttributeAsText("theKey"). Here the key is the same as the one used in

DDKObjbindSelectedKey("theKey"). But the 2nd one returns null.

let me know if I am missing anything here.

will be looking for your response.

Thanks

Former Member
0 Kudos

Hi Yasu,

Please check if you are populating the attribute properly, with something like:

final IModifiableSimpleValueSet ValueSet= wdContext.getNodeInfo().getAttribute("<attribute_name>").getModifiableSimpleType().getSVServices().getModifiableSimpleValueSet();

ValueSet.put(<key>,<value>);

The way of accessing the slectedKey for a dropdown doesn't change for dropdowns created dynamically. All that matters is if the <b>attribute</b> has been <b>created</b> at runtime. If so, you can acces the selected key as :

wdContext.currentContextElement().getAttributeValue("<name of your attribute>");

If you have created the attribute at design time, you can acces the selected value just like :

wdContext.currentContextElement().get<name of your attribute>();

Hope this helps,

Best Regards,

Nibu.

yasu_ramaiah
Explorer
0 Kudos

Hello Wilson,

Thanks for the response. As mentioned in my previous message I get a null value for the wdContext.currentContextElement().getAttributeValue("<name of your attribute>");

The only difference is that I used wdContext.currentContextElement().getAttribute"AsText"("<name of your attribute>");

-yasu

Former Member
0 Kudos

Hi Yasu,

Can you please confirm the following :

1) Are the values being displayed properly in the dropdown?

2) Is the attribute that you use, being created dynamically?

As you wrote,if you are binding the 'SelectedKey' of the dropdown as 'DDKObj.bindSelectedKey("theKey");' and if you are getting the values properly, then on selecting a value from the dropdown, the statement 'wdContext.currentContextElement().getAttributeAsText("theKey")' should return a proper value unless you initialize the attribute in wdDoModify(). If you are accessing this attribute in wdDoModify(), please check if you are setting any values for this attribute outside the 'if(firstTime){ }' block.

The statements

wdContext.currentContextElement().getAttributeAsText("theKey");

and

wdContext.currentContextElement().getAttributeValue("theKey");

will return you the same data, the first being a string representation of the key value and the second an Object representation.

Still if you have this problem, paste your relevant code here; someone among us might be able to help you !

Best Regards,

Nibu.