on 09-30-2013 5:28 AM
Hi,
I have created one application in web dynpro Java, where i have one input field and one dropdown.
My question is, how to change the dropdown values depending on the input field.
Ex: if the input field is country name and dropdown is states name, then when i give the country name, the respective state names should be reflected in the dropdown. as i change the country name, state names also should change.
Please provide me the solution for it.
Thank you
Hi Shailesh,
You can use drop-down instead of text field for your scenario.
please follow the steps:
Create the context node and attribute as in the image
note that State node comes under Country node.
Change collection cardinality to 0..n and selection cardinality to 0..1 for both the nodes
Change the "Singleton" property of State node to false.
The Country and State attributes are type of String.
Now add two DropDownByIndex UI elements and bind the Country attribute to first one and State attribute to the second.
Since you need to to change the values in the 'State' based on the 'Country' selected, create an event for Country drop-down onSelect. no need of putting any code in the event handler.
Add this code in the wdDoInit() method of the controller
String []country = {"India","USA","UK"};
//Country names; i have taken 3 countries so i'll be having multidimensional States array with 3 objects inside it
String[][]states = {{"Karnataka","Andhra Pradesh","TamilNadu","Kerala","Goa"},
{"Washington","NewYork","Chicago","Arizona","Houston"},
{"lancashire","Middlesex","Nottingham","Birmingham","Sheffield"}};
IPrivateTestDropComp1View.ICountryNode countryNode = null;
IPrivateTestDropComp1View.ICountryElement countryEle = null;
IPrivateTestDropComp1View.IStateNode stateNode = null;
IPrivateTestDropComp1View.IStateElement stateEle = null;
for (int i = 0; i < country.length; i++) {
countryNode = wdContext.nodeCountry();
countryEle = countryNode.createAndAddCountryElement();
countryEle.setCountry(country[i]); //Set the country in ith position and set the states in i,jth position
for(int j= 0; j < states[i].length; j++){
stateEle = countryNode.getCountryElementAt(i).nodeState().createAndAddStateElement();
stateEle.setState(states[i][j]);
}
}
wdContext.nodeCountry().setLeadSelection(0);
wdContext.nodeState().setLeadSelection(0);
deploy and run. Hope it helps you. Contact if you have any problem
Regards,
Prasanna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Prasanna,
there is some problem. i hope you can help me to resolve this problem. i have created the app as per you told but now the problem is, states name is not changing with respect to the country name. for all the selected country name, i am getting same states name (corresponding to the first country name).
i.e, even if i select USA and UK, i am getting
"Karnataka","Andhra Pradesh","TamilNadu","Kerala","Goa" names in dropddown.
Thank You
Hi Shailesh,
I think you haven't created action for the 'Country' drop down. Since you need to change values in 'State' drop down based on the selected 'Country', you should have an event handler for 'onSelect' of the 'Country' drop down.
Select the Drop down >> Properties >> Events >> onSelect >> Create
No need of putting any code inside the event handler.
Regards,
Prasanna
Hi Shailesh,
Please follow the below thread to populate the values.
http://scn.sap.com/thread/556251
BR,
RAM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Preferred option : Two drop downs. In country dropdown ui element, on select event, call the method to load values for the city.
If you want to use input field, based on the version you will have :
OnEnter event or OnChange event,
In these events, call the method to load the other dropdowns.
Now, to load dropdowns, refer sap help - dropdown by index / Key element.
Regards,
Sharath
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
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.