cancel
Showing results for 
Search instead for 
Did you mean: 

Adding values to Drop down list in RunTime

Former Member
0 Kudos

Hi,

How to add values to a Drop Down list in run time?

Help me on this.

Thanks,

RPN

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Thanks a lot....

I have tried both the approach. But i couldn't add value at the run time. The read only property is set to false but still i couldn't edit or add values to the DDList.

Thanks,

RPN

Edited by: RPN on Nov 19, 2008 11:35 AM

Former Member
0 Kudos

U put this method in the component controller and call that method in the view wdInit() method.

public void populateValues( )
  {
    //@@begin populateValues()
    try
    {
    	/*****POPULATING DROPDOWN BY KEY**********/
    	IWDAttributeInfo a1=wdContext.getNodeInfo().getAttribute(IPublicNewTestComp.IContextElement.DDBYKEY);
    	ISimpleTypeModifiable stm1=a1.getModifiableSimpleType();
    	IModifiableSimpleValueSet svs1=stm1.getSVServices().getModifiableSimpleValueSet();
    	
    	svs1.put("1","One");
		svs1.put("2","Two");
		
		/**************************************/
		
    }
    catch(Exception e)
    {
    	msgMngr.reportException("In populateValues "+e,false);
    }
    //@@end
  }

//@@begin others
  IWDMessageManager msgMngr;
  //@@end

Regards,

H.V.Swathi

Edited by: H.V Swathi on Nov 19, 2008 11:38 AM

Former Member
0 Kudos

>

> The read only property is set to false but still i couldn't edit or add values to the DDList.

>

Did not get your doubt.... does it got anything to do with the readonly property?

Could you share the lines of your code? What is the flow of your application?

Former Member
0 Kudos

Hi swathi,

Am facing the same problem with your suggestion too. Couldn't edit the drop down list and so i couldn't add values at run time....

Looking forward to solve the issue...

Thanks,

RPN

Former Member
0 Kudos

My requirement is: i want to add values to a drop down list at run time. Is it possible?

Former Member
0 Kudos

Hi,

It is possible through the code & explaination that has been posted earlier. It would be much better to understand what exactly you are looking for if you could elaborate your scenario.

Regards,

Anagha

Former Member
0 Kudos

Hi,

Please follow these stepts

//Initilize an arraylist to hold the dropdown data

ListOldOperationsNode=new ArrayList();

int nOldOperations=wdContext.<RFC>().size(); //Getting the size of OldOperationsNode

String strValue[]=new String[nOldOperations]; //String array to hold the data that comes from backend

for(int i=0;i<nOldOperations;i++) //rotate the loop and get the data into string array

{

strValue<i>=wdContext.nodeT_Operations().get<RFC>ElementAt(i).get<FieldName>();

}

if(strValue.length>0 && strValue!=null) //if the string array object is not equal to null and lenght is greater than zero

{

for(int j=0;j<strValue.length;j++)

{

IPrivate<VIEW NAME>.IVn<RFC>Element Oldval=

wdContext.createVnOldOperationElement();

Oldval.setVaOldOpeartionValue(strValue[j]);

ListOldOperationsNode.add(Oldval);

}

} //end if

wdContext.nodeVnOldOperation().bind(ListOldOperationsNode);

//@@end

}

Former Member
0 Kudos

Please clarify my doubts:

1. Drop Down list is writable or read only?

2. Whether user input is possible in Drop down list?

This is my scenario:

The value we are typing needs to be updated to the list while the application is running.

Means the user input should get added to the Drop down list.

Thanks,

RPN

pravesh_verma
Active Contributor
0 Kudos

Hi RPN,

I am explaining the complete method from starting. Please follow the steps:

1) Create an attribute in the context node (say: "dropDown" with datatype: String).

2) Create a new DropDownByKey UI element in the view designer.

3) Bind the attribute "dropDown" with the selectedKey property of DropDownByKey.

Now use the code snippet I have posted in the first reply.

Or use any of the code snipept given by the colleagues above. All of them are correct.

For you reference:

IModifiableSimpleValueSet valueSet = wdContext.getContext().getModifiableTypeOf("dropDown").getSVServices().getModifiableSimpleValueSet();

valueSet.put("1","1");

valueSet.put("2","2");

valueSet.put("3","3");

valueSet.put("4","4");

You can also populate this valueset with your own data, if you have it.

For example as you said: You have data in the inputfield. Lets say the data is in attribute "inpField" which is there in context node.

then use this:

String inpData = wdContext.getCurrentElement().getInpField();

valueSet.put("inpData","inpData");

If you still face some problem please let me know.

Thanks and Regards,

Pravesh

Former Member
0 Kudos

Now that you have explicitly told that user is inputting the data to be populated in drop down, your doubt is quite clear.

You may take the required elements of dropdown from user in input fields, the data will come in ur context bound to your input fields. On click of some button or some action, populate these values from your context into your dropdown.

It should work.

Former Member
0 Kudos

Thanks Pravesh.

Your idea helped me a lot.

Thanks to everyone for your valuable suggestion.

pravesh_verma
Active Contributor
0 Kudos

Hi RPN,

If the problem is solved then kindly close the thread appropriately, or if you still have some issues please let me know. Are you still stuck somewhere?

Thanks and Regards,

Pravesh

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

Use the following code

IWDAttributeInfo attributeInfo =

wdContext.getNodeInfo().getAttribute(IPrivateMain.IContextElement.COUNTRY);

ISimpleTypeModifiable countryType = attributeInfo.getModifiableSimpleType();

// Set field label and populate valueset

countryType.setFieldLabel("Country");

IModifiableSimpleValueSet valueSet =

countryType.getSVServices().getModifiableSimpleValueSet();

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

valueSet.put("Key_"i,"Country "i);

}

Regards

Padma N

Former Member
0 Kudos

Hi,

use the code below

IWDAttributeInfo attributeInfo =

wdContext.getNodeInfo().getAttribute(IPrivateMain.IContextElement.COUNTRY);

ISimpleTypeModifiable countryType = attributeInfo.getModifiableSimpleType();

// Set field label and populate valueset

countryType.setFieldLabel("Country");

IModifiableSimpleValueSet valueSet =

countryType.getSVServices().getModifiableSimpleValueSet();

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

valueSet.put("Key_"i,"Country "i);

}

Regards

Padma N

Former Member
0 Kudos

Sometimes the set of constants for a value attribute needs to be dynamically created at runtime by modifying the corresponding data type.

In many cases, the set of constants is not statically available at design time but only at runtime.

Say for e.g, You create a simple type Country. Create a node with that as data type. Do not fill

any key value pairs in it. Write it in the code so that it'll be executed only at runtime.

Populate it it with the view controller initialiszation -


//@@begin wdDoInit()
// Access interface ISimpleTypeModifiable for modifying the attribute's datatype
IWDAttributeInfo attributeInfo =
wdContext.getNodeInfo().getAttribute(IPrivateMain.IContextElement.COUNTRY);
ISimpleTypeModifiable countryType = attributeInfo.getModifiableSimpleType();
// Set field label and populate valueset
countryType.setFieldLabel("Country");
IModifiableSimpleValueSet valueSet =
countryType.getSVServices().getModifiableSimpleValueSet();
for (int i = 0; i < 40; i++){
valueSet.put("Key_"+i,"Country "+i);
}
// initialize context value attribute 'Country'
wdContext.currentContextElement().setCountry("Key_0");

The initialization of the view controller dynamically modifies the statically declared data type of the value attribute Country at runtime.

The attribute name "Country" is passed using the automatically generated constant IPrivateMain.IContextElement.COUNTRY.

This has the advantage that incorrectly written attributenames will already cause a compile error at runtime, instead of not till runtime.

Edited by: Anagha Jawalekar on Nov 19, 2008 2:59 PM

pravesh_verma
Active Contributor
0 Kudos

Hi RPN,

You can use following code snippet for filling the values to the dropdown at runtime:

IModifiableSimpleValueSet valueSet = wdContext.getContext().getModifiableTypeOf("Node_Name.Attribute_Name").getSVServices().getModifiableSimpleValueSet();
valueSet.put("1","1");
valueSet.put("2","2");
valueSet.put("3","3");
valueSet.put("4","4");

Bind the dropdown with the "Attribute_Name".

If you require any further information please let me know.

Thanks and Regards

Pravesh