cancel
Showing results for 
Search instead for 
Did you mean: 

How to set default value of DropDownByKey to first value of the list

Former Member
0 Kudos

Hi experts,

I have a Web Dynpro java application which requires me to set a default value to the DropDownByKey element. Currently the lead selection of the element is an empty string, so I would like to know how to set the default value to the first non-empty value in the list.

Any code snippet will be helpful.

Thanks,

Ju Lian

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

you should initialize attribute that mapped on selected key value of DropDownByKey - with default value

for example

property Key Value of DropDownByKey is mapped on attribute context Key

so

in wdDoInit you should write:

wdContext.currentContextElement.setKey(<default value>);

Former Member
0 Kudos

Thank you Pavel,

The problem is the values of the dropdownbykey list is dynamic, therefore it is not possible for me to set the key based on the value, I need to set the default value by index.

//Ju Lian

shankha_saha
Explorer
0 Kudos

Hi Ju Lian,

As the value list is populated at runtime, you can try below.

Create one context attribute (SUB_TYPE) which will hold the data. And create one simple dictionary type object(SUB_TYPE) without any value in enumeration tab and assign this as a type to the context attribute(SUB_TYPE).

In the coding area write the below code to generate the list with runtime data

IWDAttributeInfo attributeInfo = wdContext.getNodeInfo().getAttribute(IPrivateTestView.IContextElement.SUB_TYPE);

ISimpleTypeModifiable subType = attributeInfo.getModifiableSimpleType();

subType.setFieldLabel("Test Fields");

subType.setDefaultValue(wdContext.currentContextElement().getAtt1())

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

valueSet.clear();

valueSet.put(wdContext.currentContextElement().getAtt2(), wdContext.currentContextElement().getAtt2_1());

valueSet.put(wdContext.currentContextElement().getAtt3(), (wdContext.currentContextElement().getAtt4());

The default value will be the Att1 . Organize imports for missing imports.

Thanks

Shankha

Edited by: Shankha_Saha on Feb 1, 2012 8:03 AM

govardan_raj
Contributor
0 Kudos

hi

if you are doing svs for an attibute dynamically that is run time , then to set the DDBykey To first value by default is simple as shown


IWDAttributeInfo attributeInfo = wdContext.nodeVnOrderList().getNodeInfo().getAttribute(IPrivateSlsOrdListView.IVnOrderListElement.VA_I__STATUS);
		ISimpleType simpleType = attributeInfo.getSimpleType();
		ISimpleValueSet valueset = simpleType.getSVServices().getValues();
		//Object key = element.getAttributeValue(attributeName);
		if(valueset.size() > 0)
		{
			wdContext.currentVnOrderListElement().setVaI_Status(valueset.getKey(0).toString());	
		}

in the above code the status is the attribute for which the svs is done and it is binded to DDBKey ul element

and rest all u can understand from the code.......

p330068
Active Contributor
0 Kudos

Dear Ju Lian,

When you populate the DropDownByKey, you will use like :-


//CODE FOR POPULATING DATA FOR DropDownByKey
IWDAttributeInfo attributeInfo = wdContext.node<NODE NAME123>().getNodeInfo().getAttribute("<ATTRIBUTE123>");	
ISimpleTypeModifiable var = attributeInfo.getModifiableSimpleType();
svs = var.getSVServices().getModifiableSimpleValueSet();
svs.clear();

svs.put("0".toString(), "Select".toString());	
			
if(list.size()==0){
       wdComponentAPI.getMessageManager().reportException("No Data Available.",true);
}else{			
        for(int i=0;i<<DYNAMIC NODE>.size();i++){			
             svs.put(<DYNAMIC KEY>, <DYNAMIC VALUE>);				
         }
}

//CODE FOR DEFULT VALUE SETTING FOR DropDownByKey
IWDAttributeInfo nodeInfo = wdContext.node<NODE NAME123>().getNodeInfo().getAttribute("<ATTRIBUTE123>");
ISimpleType simpleType = nodeInfo.getSimpleType();
ISimpleValueSet valueSet = simpleType.getSVServices().getValues();
wdContext.current<NODE NAME123>Element().set<ATTRIBUTE123>(valueSet.getText(valueSet.getKey(0).toString()));

Hope it will resolve your issue.

Best Regards

Arun Jaiswal

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Set the attirbute value to one of the values present in the value set and it will come as default in the dropdown.

These links may be helpful

http://help.sap.com/saphelp_nw70/helpdata/en/bb/69b441b0133531e10000000a155106/content.htm

Forum

http://forums.sdn.sap.com/thread.jspa?threadID=1863848

Thanks,

Jyothi.

Former Member
0 Kudos
govardan_raj
Contributor
0 Kudos

hi

if you are doing svs for an attibute dynamically that is run time , then to set the DDBykey To first value by default is simple as shown


IWDAttributeInfo attributeInfo = wdContext.nodeVnOrderList().getNodeInfo().getAttribute(IPrivateSlsOrdListView.IVnOrderListElement.VA_I__STATUS);
		ISimpleType simpleType = attributeInfo.getSimpleType();
		ISimpleValueSet valueset = simpleType.getSVServices().getValues();
		//Object key = element.getAttributeValue(attributeName);
		if(valueset.size() > 0)
		{
			wdContext.currentVnOrderListElement().setVaI_Status(valueset.getKey(0).toString());	
		}

in the above code the status is the attribute for which the svs is done and it is binded to DDBKey ul element

and rest all u can understand from the code.......