cancel
Showing results for 
Search instead for 
Did you mean: 

Populating a dropdown from SQL database

Former Member
0 Kudos

Hi all,

I am getting a List from the database and I wish to populate a dropdownbykey element in webdynpro with this list. What is the correct method to do this? I have tried setting the dropdown from the context, but this did not help.

Please suggest some solution.

Thanks,

Mayuri

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Mayuri,

Do the following

1. Create a value attribute(say myValues) of type String in view Context

2. Bind myValues to the value property of DDByKey

3. After the code for getting the values from DB, add the following code

IWDAttributeInfo atInfo=wdContext.getNodeInfo().getAttribute(IPrivate<ViewName>.IContextElement.MY_VALUES);

ISimpleTypeModifiable stm=atInfo.getModifiableSimpleType();

IModifiableSimpleValueSet svs=stm.getSVServices(). getModifiableSimpleValueSet();

svs.put("KEY1","VALUE1 FROM ResultSet");

svs.put("KEY2","VALUE2 FROM ResultSet");

svs.put("KEY3","VALUE3 FROM ResultSet");

Thanks

Fahad Hamsa

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi

Create one context attribute and write the following code and make the changes as per your requirement.

IWDAttributeInfo valueInfo = wdContext.getNodeInfo().getAttribute(IPrivateControlPanelView.IContextElement.NAME);

ISimpleTypeModifiable valueType = valueInfo.getModifiableSimpleType();

// Set field label and populate valueset

valueType.setFieldLabel("Name");

// create a method with arraylist as the return type in your controller

ArrayList list = wdThis.wdGetController.getList ();

IModifiableSimpleValueSet valueSet = valueType.getSVServices().getModifiableSimpleValueSet();

if( list != null ) {

for (int index = 0 ; index < list.size() ; index ++ ) {

HashMap row = new HashMap();

if (row != null){

row = (HashMap) shiptoList.get(index);

keyValue = row.get ("KEY_VALUE");

keyName = row.get ("KEY_NAME");

valueSet.put (keyValue, keyName);

}

}

// in getList method of your controleler write the following code.

public ArrayList getList () {

ArrayList list = new ArrayList ();

while (rs.next ()) {

Map row = new HashMap ();

row.put ("KEY_NAME", rs.getString(1));

row.put ("KEY_VALUE", rs.getString (2));

// add row data to the arraylist

list.add (row);

}

return list;

}

Regards

Suresh