Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Change in dropdown values based on input value

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

Former Member
Former Member replied

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

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question