cancel
Showing results for 
Search instead for 
Did you mean: 

Drop down code for cities on selection of related state dropdown

Former Member
0 Kudos

Dear all

Please adjust the below coading for two drop downs when iam selection any state getting default cites in cite dropdown

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)

{ }

Accepted Solutions (1)

Accepted Solutions (1)

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

Edited by: Tushar Sinha on Nov 18, 2009 3:40 AM

Former Member
0 Kudos

my code is working fine but when iam selecting the state of andhra related cites iam getting but at the same time when iam selecting other states iam getting same cites of andhra

already iam using the extra node for state and city

plz adjust below code which iam already using,i cant use ur code.

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("13"); input.setCity("VASA");

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){ }

Former Member
0 Kudos

Hi Kishore,

What seems to be the issue is you are not invalidating the City Node onActionSelectDropDownForRegion which is bound to the Cities Dropdown list. So, what happens is everytime you go for selecting a new Region from the drop down, the earlier values of cities in Cities Dropdown are not cleared and at the same time new cities for the new region are added. Please insert the code at the very beginning line of the onSelect action of Region Drop down:

wdContext.node<CityNode>.invalidate();

Please check. If this is not the issue then it might be possible that you are not passing the correct(currently selected) Region code to the BAPI to retrieve the cities belonging to it. Check if only the first element is getting passed all the time.

Get current region selection using:

wdContext.current<RegionNode>Element().get<RegionCode>();

For this print the passed Region Code to BAPI under onSelectAction of Region Dropdown list and the size of CityNode everytime.

wdComponentAPI.getMessageManager().reportSuccess("Region Code: " + wdContext.current<RegionNode>Element().get<RegionCode>());

wdComponentAPI.getMessageManager().reportSuccess("City Node Size: " + wdContext.node<CityNode>().size());

Regards,

Tushar Sinha

Former Member
0 Kudos

Hi Kishore,

What now seems to be the issue is you have created seperate Model Node in the View Controller Zhrblood_Group_Input for the BAPI Zhrblood_Group and after you have bound it to Zhrblood_Group_Input structure node of the model imported you have even bound the drop downs for Region, City, BloodGp, Rhfactor to the Nodes within the Parament Model Node. Everytime you call this bapi, new values are getting set to City Node without invalidating the previous node.

So just after

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

statement, invalidate the Output node under Zhrblood_Group_Input node to delete the earlier values and refresh the output node.

wdContext.nodeZhrblood_Group_InputElement().nodeOutput().invalidate();

Moreover, I can see that you have hard coded the values to be passed in the input structure of the Model Node. So, everytime the same result will be given by the BAPI irrespective of the current value for region selected in the dropdown. You actually have to pick the current element value from the context. Have a look.

Zhrblood_Group_Input input=new Zhrblood_Group_Input();

wdContext.nodeZhrblood_Group_Input().bind(input);

input.setMode("DIS");

input.setStatecode("13");

input.setCity("VASA");

input.setRhfactor("03");

input.setBlood_Gp("01");

Like for setting State, use

input.setStatecode(wdContext.node<State>().current<State>Element().get<StateCode>());

So, i will suggest you to create seperate Context Nodes for Region, City, BloodGp and RhFactor and have context attribute for them. Then, bind them to the drop down UI elements in the Layput of the View Controller.

That should solve your problem.

Regards,

Tushar Sinha

Answers (0)