cancel
Showing results for 
Search instead for 
Did you mean: 

Problems while setting values to Drop-down with key

Former Member
0 Kudos

Hello

I am having two drop-down list in which the values of the second one depends on the first one. I have implemented following code from help.sap.com.Here I am getting Name and value from the backend. This code is implemented in method <b>"wdDoModifyView"</b> as suggested over there.

<b>***************************************Start Code****************************************

if(!firstTime)

{

IWDDropDownByKey ddlist = (IWDDropDownByKey)view.createElement(IWDDropDownByKey.class,"my_ddlist");

ISimpleTypeModifiable myType = wdThis.wdGetAPI().getContext().getModifiableTypeOf("context_attribute");

IModifiableSimpleValueSet values = myType.getSVServices().getModifiableSimpleValueSet();

int i_tmp = wdContext.nodeResult().size();

for(int i=0;i< i_tmp;i++)

{

values.put(wdContext.currentResultElement().getName(),wdContext.currentResultElement().getValue());

wdContext.nodeResult().movePrevious();

}

}

***************************************End Code*****************************************</b>

When I try to select first value then it gives following error

<b>"Cannot add element with duplicate ID "my_dd" of type com.sap.tc.webdynpro.clientserver.uielib.standard.impl.DropDownByKey "</b>.

I checked whether the model is returning duplicate values but it was not.

Thanks in advance.

Regards

Rajeev

Accepted Solutions (1)

Accepted Solutions (1)

lajitha_menon
Contributor
0 Kudos

Hi there,

check the id of the dropdownby keys that you have or trying to create dynamically. They seem to be the same - from the error. You have to give different ids to the dropdowns.

Regards,

LM

PS: Do you really want to create these elements dynamically. If there is no specific reason, then its a lot simpler to create 2 dropdowns. You can set the values based on the values of another dropdown, if you write your code in the onSelect event of the first dropdown.

Answers (3)

Answers (3)

Former Member
0 Kudos

Rajeev,

If you want just to fix problem, with your existing implementation, then simply do not create IWDDropDownByKey controls dynamically (both my_ddlist and my_dd) but rather alter modifiable simple type only (and create controls at design-time). Btw, error mentions control my_dd that is not shown in your code, most probably you are re-creating "first" DropDown in wdDoModifyView as well.

However, I'd rather like to suggest you revisit design of your component view. Try to accomplish your task with DropDownByIndex. This way you just need 2 nested nodes (master-dependent) where dependent node has own supply function and populates its values based on parent (master) element. This way you may avoid dynamic UI programming altogether.

Valery Silaev

SaM Solutions

http://www.sam-solutions.net

Former Member
0 Kudos

Hi Rajeev,

If you already have 2 dropdowns then why do you create one more in your code?

Guess you should just use something like:

if(!firstTime)
{
ISimpleTypeModifiable myType = wdThis.wdGetAPI().getContext().getModifiableTypeOf("context_attribute");
IModifiableSimpleValueSet values = myType.getSVServices().getModifiableSimpleValueSet();
int i_tmp = wdContext.nodeResult().size();

for(int i=0;i< i_tmp;i++)
{
values.put(wdContext.currentResultElement().getName(),wdContext.currentResultElement().getValue());
wdContext.nodeResult().movePrevious();
}
}

The result node is bound to your second dropdown ofcourse.

Regards,

Satyajit.

Former Member
0 Kudos

Hi Rajeev,

Where you are creation DropDownByKey with id "my_dd".

Bcose in the exception its showing id as "my_dd" but i can't see this in the code .

Regards, Anilkumar