on 11-19-2008 9:09 AM
Hi,
How to add values to a Drop Down list in run time?
Help me on this.
Thanks,
RPN
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
}
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
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
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.