cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a Dynamic drop down box by key?

Former Member
0 Kudos

Hi All,

I have a drop down box populated with values.Now on the selection of any value in this drop down , the adjacent drop down box should get populated.

Can any one write some code snippet to make this easy for me.

Relevant answers will be appreciated and awarded.

Regards

DK

Accepted Solutions (1)

Accepted Solutions (1)

sridhar_k2
Active Contributor
0 Kudos

Hi DK,

It is very simple. For the first DropDown you just assign a action.This action will be called whenever you select any element in the DropDown.

In this method, just populate elements for the second drop down.


IWDAttributeInfo aInfo=wdContext.getNodeInfo().getAttribute("Currency");
if(aInfo!=null){
IModifiableSimpleValueSet valSet=aInfo.getModifiableSimpleType().getSVServices().getModifiableSimpleValueSet();
for(int i = 0;i<3;i++){
valSet.put("i"+1,"i"+1);
}

//Currency is your context element, which is binded to

2nd dropdown.

//ValSet, u can keep values, statically or dynamically.

Reply me, if you struck .

Regards,

SK

Answers (2)

Answers (2)

saraswathi_d
Participant
0 Kudos

Hi,

Follow the below procedure

1. First you create two simple types in dictionary -->local dictionary->simple types. Go to enumeration tab enter the values (whatare the values you need to display in the first drop down)

Ex: first level

Doc_ documents

QBANK_ Question bank

2.Enter the values in second simple type enter the secondlevel dropdown values.

Ex: Secondlevel

Doc_P PlainDocs

Doc_R Reports

QBANK_F Functional

QBANK_T Technical

3. Create three context attributes

Ex: FirstLevel

SecondLevel

SecondLevel

All

4. If you want to display the second dropdown after selecting the first dropdown. Create one context attribute called visibility--> set property data type as visibility

5. Create two dropdown UI elements. Bound these dropdowns with wit the context atrributes.

6 Create one action and one method.

Go to implementation. Sample code id below.

public void wdDoInit()

{

//@@begin wdDoInit()

fillValueSet(true);

//@@end

}

public void fillValueSet( boolean initialize )

{

//@@begin fillValueSet()

IWDNodeInfo nodeInfo=wdContext.getNodeInfo();

IWDNodeElement element=wdContext.currentContextElement();

String choice1=element.getAttributeAsText("LevelOne");

IModifiableSimpleValueSet LevelTwoAll_SV=nodeInfo.getAttribute("LevelTwoAll").getModifiableSimpleType().getSVServices().getModifiableSimpleValueSet();

IModifiableSimpleValueSet LevelTwo_SV=nodeInfo.getAttribute("LevelTwo").getModifiableSimpleType().getSVServices().getModifiableSimpleValueSet();

LevelTwo_SV.clear();

String LevelTwo=element.getAttributeAsText("LevelTwo");

if(LevelTwo!=null)

{

if(!LevelTwo.startsWith(choice1))

{

element.setLevelTwo("");

}

}

for(int i=0;i<LevelTwoAll_SV.size();i++)

{

if(initialize || LevelTwoAll_SV.getKey(i).toString().startsWith(choice1))

{

LevelTwo_SV.put(LevelTwoAll_SV.getKey(i),LevelTwoAll_SV.getText(i));

}

}

//@@end

}

public void onActionFilterValues(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionFilterValues(ServerEvent)

fillValueSet(false);

//@@end

}

Regards,

Saraswathi.

Hi,

Sorry by mistake i ahve written the procedure for design time dropdown

This is the sample code for Dynamic ui elements creation. Instead of Input field you can dropdown.

subInputField<i> =(IWDInputField) view.createElement(IWDInputField.class,"Subject" + i);

wdThis.wdGetContext().getContext().getRootNodeInfo().addAttribute("subjectloop"+i, "ddic:com.sap.dictionary.string");

wdThis.wdGetContext().getCurrentElement().setAttributeValue("subjectloop"+i, subject1<i>);

subInputField<i>.bindValue(wdThis.wdGetContext().getNodeInfo().getAttribute("subjectloop"+i));

group<i>.addChild(subInputField<i>);

Pls reward points for useful info

Message was edited by: Saraswathi D

Former Member
0 Kudos

Hai Dipendra,

Create Valuenode X under this create a value attribute y in context.

Dnd two DorpdownbyIndex UI elements.

Bind first one with your data, and bind second one with X.

Create Action onSelectedFirst() to First dropdown .

write this code in above acion

onSelectedFirst{

ArrayList al=new ArrayList();

for(int i=0;i<8;i++){

IprivateYOURView.IXElement ele=wdContext.createXElement();

ele.setY(""+i);

al.add(ele);

}

wdContext.nodeX().bind(al);

}

Hope this will solve your problem.

regards,

Naga Raju