cancel
Showing results for 
Search instead for 
Did you mean: 

Populating a city dropdown based on state dropdown selection

Former Member
0 Kudos

Dear all

Below code output is when iam selecting STATE DROP DOWN for example ANDHRA(state) it was give all ANDHRA related CITES in CITES drop down but when iam selecting MAHARASTRA(state) in dropdown it was giving same ANDHRA cites.Please help me in solving this problem.iam getting same cites for all states.

public void wdDoInit()

{

//@@begin wdDoInit()

int asize =0;

String key="";

String value="";

IWDMessageManager msgMrg = wdThis.wdGetAPI().getComponent().getMessageManager();

Zhrblood_Group_Input input=new Zhrblood_Group_Input();

wdContext.nodeZhrblood_Group_Input().bind(input);

input.setMode("DIS");

input.setStatecode("1");

input.setCity("0001");

input.setRhfactor("03");

input.setBlood_Gp("01");

try

{ wdContext.currentZhrblood_Group_InputElement().modelObject().execute(); }

catch(Exception e)

{ String msg = e.getLocalizedMessage();

if ((msg==null) || (msg.length()==0))

{ msg = e.getMessage(); }

msgMrg.reportException(e.toString(),true);

}

try

{ IWDAttributeInfo stinfo = wdContext.getNodeInfo().getAttribute(IPrivateOverview_bloodgroup.IContextElement.CTX__STATE);

IWDAttributeInfo ctinfo = wdContext.getNodeInfo().getAttribute(IPrivateOverview_bloodgroup.IContextElement.CTX__CITY);

IWDAttributeInfo bginfo = wdContext.getNodeInfo().getAttribute(IPrivateOverview_bloodgroup.IContextElement.CTX__BLOODGROUP);

IWDAttributeInfo rhinfo = wdContext.getNodeInfo().getAttribute(IPrivateOverview_bloodgroup.IContextElement.CTX__RHFACTOR);

ISimpleTypeModifiable sttype = stinfo.getModifiableSimpleType();

ISimpleTypeModifiable cttype = ctinfo.getModifiableSimpleType();

ISimpleTypeModifiable bgtype = bginfo.getModifiableSimpleType();

ISimpleTypeModifiable rhtype = rhinfo.getModifiableSimpleType();

IModifiableSimpleValueSet stset = sttype.getSVServices().getModifiableSimpleValueSet();

IModifiableSimpleValueSet ctset = cttype.getSVServices().getModifiableSimpleValueSet();

IModifiableSimpleValueSet bgset = bgtype.getSVServices().getModifiableSimpleValueSet();

IModifiableSimpleValueSet rhset = rhtype.getSVServices().getModifiableSimpleValueSet();

asize = wdContext.nodeIt_State().size();

for(int i=0;i<asize;i++)

{ key = wdContext.nodeIt_State().getIt_StateElementAt(i).getAttributeAsText("Statecode");

value = wdContext.nodeIt_State().getIt_StateElementAt(i).getAttributeAsText("Statenm");

stset.put(key,value);

}

asize = wdContext.nodeIt_City().size();

for(int i=0;i<asize;i++)

{ key = wdContext.nodeIt_City().getIt_CityElementAt(i).getAttributeAsText("Psa");

value = wdContext.nodeIt_City().getIt_CityElementAt(i).getAttributeAsText("Btext");

ctset.put(key,value);

}

asize = wdContext.nodeIt_Bloodgp().size();

for(int i=0;i<asize;i++)

{ key = wdContext.nodeIt_Bloodgp().getIt_BloodgpElementAt(i).getAttributeAsText("Wtfld");

value = wdContext.nodeIt_Bloodgp().getIt_BloodgpElementAt(i).getAttributeAsText("Stext");

bgset.put(key,value);

}

asize = wdContext.nodeIt_Rhfact().size();

for(int i=0;i<asize;i++)

{ key = wdContext.nodeIt_Rhfact().getIt_RhfactElementAt(i).getAttributeAsText("Wtfld");

value = wdContext.nodeIt_Rhfact().getIt_RhfactElementAt(i).getAttributeAsText("Stext");

rhset.put(key,value);

}

}

catch(Exception ex)

{ }

Regards

KISHORE

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

These questions have been answered in the forum quite a few times. A simple search for "two dropdown" would yield results like [this|]. Follow Armin Reichert's reply to that thread.

Regards,

Satyajit

Former Member
0 Kudos

hi

Please adjust the below coading iam new to webdynpro for java.

public void wdDoInit()

{

//@@begin wdDoInit()

int asize =0;

String key="";

String value="";

IWDMessageManager msgMrg = wdThis.wdGetAPI().getComponent().getMessageManager();

Zhrblood_Group_Input input=new Zhrblood_Group_Input();

wdContext.nodeZhrblood_Group_Input().bind(input);

input.setMode("DIS");

input.setStatecode("1");

input.setCity("0001");

input.setRhfactor("03");

input.setBlood_Gp("01");

try

{ wdContext.currentZhrblood_Group_InputElement().modelObject().execute(); }

catch(Exception e)

{ String msg = e.getLocalizedMessage();

if ((msg==null) || (msg.length()==0))

{ msg = e.getMessage(); }

msgMrg.reportException(e.toString(),true);

}

try

{ IWDAttributeInfo stinfo = wdContext.getNodeInfo().getAttribute(IPrivateOverview_bloodgroup.IContextElement.CTX__STATE);

IWDAttributeInfo ctinfo = wdContext.getNodeInfo().getAttribute(IPrivateOverview_bloodgroup.IContextElement.CTX__CITY);

IWDAttributeInfo bginfo = wdContext.getNodeInfo().getAttribute(IPrivateOverview_bloodgroup.IContextElement.CTX__BLOODGROUP);

IWDAttributeInfo rhinfo = wdContext.getNodeInfo().getAttribute(IPrivateOverview_bloodgroup.IContextElement.CTX__RHFACTOR);

ISimpleTypeModifiable sttype = stinfo.getModifiableSimpleType();

ISimpleTypeModifiable cttype = ctinfo.getModifiableSimpleType();

ISimpleTypeModifiable bgtype = bginfo.getModifiableSimpleType();

ISimpleTypeModifiable rhtype = rhinfo.getModifiableSimpleType();

IModifiableSimpleValueSet stset = sttype.getSVServices().getModifiableSimpleValueSet();

IModifiableSimpleValueSet ctset = cttype.getSVServices().getModifiableSimpleValueSet();

IModifiableSimpleValueSet bgset = bgtype.getSVServices().getModifiableSimpleValueSet();

IModifiableSimpleValueSet rhset = rhtype.getSVServices().getModifiableSimpleValueSet();

asize = wdContext.nodeIt_State().size();

for(int i=0;i<asize;i++)

{ key = wdContext.nodeIt_State().getIt_StateElementAt(i).getAttributeAsText("Statecode");

value = wdContext.nodeIt_State().getIt_StateElementAt(i).getAttributeAsText("Statenm");

stset.put(key,value);

}

asize = wdContext.nodeIt_City().size();

for(int i=0;i<asize;i++)

{ key = wdContext.nodeIt_City().getIt_CityElementAt(i).getAttributeAsText("Psa");

value = wdContext.nodeIt_City().getIt_CityElementAt(i).getAttributeAsText("Btext");

ctset.put(key,value);

}

asize = wdContext.nodeIt_Bloodgp().size();

for(int i=0;i<asize;i++)

{ key = wdContext.nodeIt_Bloodgp().getIt_BloodgpElementAt(i).getAttributeAsText("Wtfld");

value = wdContext.nodeIt_Bloodgp().getIt_BloodgpElementAt(i).getAttributeAsText("Stext");

bgset.put(key,value);

}

asize = wdContext.nodeIt_Rhfact().size();

for(int i=0;i<asize;i++)

{ key = wdContext.nodeIt_Rhfact().getIt_RhfactElementAt(i).getAttributeAsText("Wtfld");

value = wdContext.nodeIt_Rhfact().getIt_RhfactElementAt(i).getAttributeAsText("Stext");

rhset.put(key,value);

}

}

catch(Exception ex)

{ }

Regards,

Edited by: kishore shikore on Nov 17, 2009 8:15 PM

Former Member
0 Kudos

Hi Kishore,

I have adjust your code as mentioned below. It is all I could do.

Create two DropDownByIndex UI Elements under layout of the View Controller to display Regions and Cities.

Add following code in wdDoInit of the view-->

public void wdDoInit(){

//Create a Context Node Vn_Region and Context Node Attributes Va_Region and Va_RegionCode under it. This stores all the Regions with their Names and Codes. Now create all the element for this node to show all the regions like West Bengal, Maharashtra, Andhra......... Bind the Region Drop Down value to the Va_Region node attribute.

String [] regions = {"Andhra Pradesh", "Arunachal Pradesh", "Andaman and Nicobar", ........};

String [] regionsCode = {"01", "02". "03",.............};

IPrivateTestView.IVn_RegionElement regEle = null;

//Make sure the node of regions mentioned is equal to number of Codes.

for(int i=0; i<regions.length(); i++){

regEle = wdContext.createVn_RegionElement();

regEle.setVa_Region(regions<i>);

regEle.setVa_RegionCode(regionsCode<i>);

wdContext.nodeVn_Region().addElement(regEle);

}

Now create an Action GetCitiesForRegion and bind it to onSelect property of the Region Drop Down list.

Put following codes in the Action created-->

public void onActionGetCitiesForRegion() {

//Create a Context Node Vn_City and Context Node Attribute Va_City under it. This stores all the Cities belonging to the selected Region from the Drop Down. The cities for the selected Region are returned from BAPI and are displayed as various options under City Drop Downlist. Bind the Va_Cities attribute with Drop Down List for displaying Cities in Layout of the View Controller.

/To delete the existing values (elements of the Vn_Cities node) of the drop down if BAPI is called earlier and insert the newly retrieved cities for the region from the BAPI to the Vn_City node./

wdContext.node<Cities>.invalidate();

//Create UI element Message Manager in Layout and place wherever required.

//Get the MessageManager to set Messages (Success/Exception)

IWDMessageManager msgMrg = wdComponentAPI().getMessageManager();

//Create a BAPI instance of the Input Node

Zhrblood_Group_Input input=new Zhrblood_Group_Input();

//Create a Model Node Mn_GetCities and bind it to the imported BAPI Zhrblood_Group at Zhrblood_Group_Input() structure level.

//Bind the Bapi instance to the Model Node Mn_GetCities

wdContext.nodeMn_GetCities().bind(input);

//Pass the Select Region's code as input parameter to BAPI

input.setState(wdContext.currentVn_RegionElement().getVa_RegionCode);

try {

wdContext.currentMn_GetCitiesElement().modelObject().execute();

wdContext.node<Output Node under Model Node Mn_GetCities>.invalidate;

IPrivateTestView.IVn_CityElement cityEle = null;

for(int iC=0; iC<wdContext.node<Cities Node under Mn_GetCities-Output>.size(); iC++){

cityEle = wdContext.createVn_CityElement();

cityEle.setVa_City(wdContext.node<Cities Node under Mn_GetCities-Output>.getCitiesElementAt(iC).getCity);

wdContext.nodeVn_City().addElement(cityEle);

}

} catch(Exception e) {

String msg = e.getLocalizedMessage();

if ((msg==null) || (msg.trim().equalsIgnoreCase("")))

{

msg = e.getMessage();

}

msgMrg.reportException(msg,true);

}

}

Let me know if you still have issue.

Regards,

Tushar Sinha

Answers (0)