Skip to Content
avatar image
Former Member

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Sep 30, 2013 at 08:39 AM

    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

    Capture.PNG

    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.

    Capture1.PNG

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 30, 2013 at 07:29 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 30, 2013 at 07:37 AM

    Hi Shailesh,

    Please follow the below thread to populate the values.

    http://scn.sap.com/thread/556251

    BR,

    RAM

    Add comment
    10|10000 characters needed characters exceeded