cancel
Showing results for 
Search instead for 
Did you mean: 

Populate elements in DDK

Former Member
0 Kudos

Hi All,

I have a scenario where I'm using 3 Drop down by Keys in a webdynpro Application.

I have created a structure called country and binded it to the context for the 1st DDK.

Depending on the selection of country the next two DDK elements should get populated.

for example if the country is selected as India, the next DDK should represent the states like Andhra pradesh, karnataka..etc and the 3rd DDK should contain cities of their respective states.

I have created the other two structures for state and cities.

Could any one help me and advise me how to proceed on this.

regards

ambicasony

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

try this.


public void fillMaster( )
  {
    //@@begin fillMaster()
    String data[][] = { {"India", "Kerala", "Trivandrum"},
    					{"India", "Kerala", "Kochin"},
    					{"India", "Maharashtra", "Mumbai"},
    					{"India", "Maharashtra", "Pune"},
    					{"USA", "New York", "Albany"},
    					{"USA", "Georgia", "Atlanta"},
    					{"USA", "Arizona", "Phoenix"},
    					{"USA", "Florida", "Tallahassee"},
    					{"USA", "Texas", "Austin"}};
    IPublicExp_1.IMasterElement master;					
    for( int i = 0; i < data.length; i++){
    	master = wdContext.createMasterElement();	
    		master.setCountry( data[ i][ 0]);
    		master.setState( data[ i][ 1]);
			master.setRegion( data[ i][ 2]);
		wdContext.nodeMaster().addElement( master);	
    }
    //@@end
  }

Adding Country/ States/ Region


private void addCountry(){
  		String country = "";
  		IWDAttributeInfo cntinfo = wdContext
  										.nodeChild()
  										.getNodeInfo()
  										.getAttribute( "Country");
  		ISimpleTypeModifiable sim = cntinfo.getModifiableSimpleType();
  		IModifiableSimpleValueSet valset = sim
  											.getSVServices()
  											.getModifiableSimpleValueSet();
  		valset.clear();									
  		IPublicExp_1.IMasterNode masternode = wdContext.nodeMaster();									
  		for( int i = 0; i < masternode.size(); i++){
  			country = masternode
  							.getMasterElementAt( i)
  							.getCountry();
  			valset.put( country, country);									 								
  		}							
  	}
  	private void addState(){
		String state = "";
		IWDAttributeInfo cntinfo = wdContext
										.nodeChild()
										.getNodeInfo()
										.getAttribute( "State");
		ISimpleTypeModifiable sim = cntinfo.getModifiableSimpleType();
		IModifiableSimpleValueSet valset = sim
											.getSVServices()
											.getModifiableSimpleValueSet();
		valset.clear();									
		IPublicExp_1.IMasterNode masternode = wdContext.nodeMaster();
		IPublicExp_1.IMasterElement masterele;									
		for( int i = 0; i < masternode.size(); i++){
			masterele = masternode
							.getMasterElementAt( i);
			if( masterele.getCountry().equalsIgnoreCase( wdContext.currentChildElement().getCountry()))
				state = masterele.getState();				
				valset.put( state, state);									 								
		}
  	}
  	

Call method on action of drop downs


 public void fillCountry( )
  {
    //@@begin fillCountry()
    	addCountry();
    //@@end
  }

  //@@begin javadoc:fillState()
  /** Declared method. */
  //@@end
  public void fillState( )
  {
    //@@begin fillState()
	addState();
    //@@end
  }

vinod v

Former Member
0 Kudos

Hi Vinod,

I will try this code and let u know.

Regards

ambicasony

Former Member
0 Kudos

Hi Vinod,

Could you explain me step by step in creating this application.

By using the above code, iam getting empty drop down boxes.

please find the below procedure which i followed.

1.Created 3 DDK's,created 3 context attributes Country,State,Region under the Node Master.

2. Binded the selected key of DDKs to respective attributes.

3. Created two actions( fill Country, fill state) and two methods ( addCountry,addState).

4. i have copied the fill master code in wddoinit method, and reamaining as you mentioned above.

Please Advice anybody

regards

ambicasony

Edited by: ambica sony on Feb 6, 2009 12:57 PM

Former Member
0 Kudos

<Msg Removed.>

Former Member
0 Kudos

Hi Chandranna,

Thanks for your reply.

In order to follow your procedure than I need to create some 30 - 40 enumerations.

Is there any other procedure where the 3 DDk will be visible in the view but on the selection criteria of the 1st DDK, the elements should get populated in 2nd and 3rd DDK .

Can we achevie this dynamically.

If yes, please suggest me how to proceed.

Regards

ambicasony

Former Member
0 Kudos

Hi,

I am afraid there is no such way.

This was the most efficient method. You will have to create enumerations for Countries, States and Cities.

I suggest you follow this method since creating enumerations and modifying them later are more easier.

Regards

Kishan

Former Member
0 Kudos

Ambika,

Please specify the source of all Country/State/Region data? JDBC/RFC or directly hard coding values to context.. ?

vinod v

Former Member
0 Kudos

Hi Vinod,

It is directly hard coding of values.

Could you help me how to achieve this.

Regards

ambicasony

Former Member
0 Kudos

Hi,

If you are hardcoding the values you can use the code mentioned by Sathish in the above posts and fill the dropdown values accordingly. Here is the sample code explaining again

IWDAttributeInfo attributeInfo_region = nodeinfo_region

.getAttribute(<Context attrib of type string bound to country dropdown UI element>);

ISimpleTypeModifiable regionType = attributeInfo_region.getModifiableSimpleType();

IModifiableSimpleValueSet valueSet_country =regionType.getSVServices().getModifiableSimpleValueSet();

valueSet_country.clear();

for (int i = 0; i < No of Elements to insert; i++)

{

region = wdContext.nodeReturnGetAllRegionDetails().getReturnGetAllRegionDetailsElementAt(i);

valueSet_country.put(<key1>, <value1>);

}

You can use the above code to fetch from node and fill the dropdown also.

Or use Enumeration as Kishan suggested.

Wrap the above code in a method to fill States and Cities and you can call the method onSelect event of the dropdown key element

Hope it is clear

Regards,

Santhosh

former_member185086
Active Contributor
0 Kudos

Hi,

Please follow the steps:

1.Create 3 method in Comp .

  • first method will have no parameter,but other two have as

getAllCountry()

getAllState(countryID)

getAllCities(StateID)

2. Code for each method to populate the data from either webservice/ejb/rfc

IPublicAdminComp.IReturnGetAllRegionDetailsElement region;

IWDNodeInfo nodeinfo_region = wdContext.nodeCityDetails().getNodeInfo();

IWDAttributeInfo attributeInfo_region = nodeinfo_region

.getAttribute(IPublicAdminComp.ICityDetailsElement.REGION_CODE);

ISimpleTypeModifiable regionType = attributeInfo_region.getModifiableSimpleType();

IModifiableSimpleValueSet valueSet_region =regionType.getSVServices().getModifiableSimpleValueSet();

valueSet_region.clear();

for (int i = 0; i < wdContext.nodeReturnGetAllRegionDetails().size(); i++)

{

region = wdContext.nodeReturnGetAllRegionDetails().getReturnGetAllRegionDetailsElementAt(i);

valueSet_region.put(region.getRegioncode(), region.getRegionname());

}

Note : say this is value help for first method getAllCountry

3.On the action of first dropdown call the second method with selected id as it parameter.

4.remember that if you want values for third dropdown , you have to called its respective method in second

dropdown .

Best Regards

Satish

Former Member
0 Kudos

Hi,

Try this code in the wdModifyView(),


//get an alias to the DDBK1 to DDBK3
IWDDropDownByKey key1 = (IWDDropDownByKey) view.getElement("DropDownByKey1"); 
//here DropDownByKey1 should be the name/ID of the DDBK you have created at design time. 
//Change it according to the name of your first DDBK
IWDDropDownByKey key2 = (IWDDropDownByKey) view.getElement("DropDownByKey2");
//Change it according to the name of your second DDBK
IWDDropDownByKey key3 = (IWDDropDownByKey) view.getElement("DropDownByKey3");
//Change it according to the name of your third DDBK
 
if (key1.getSelectedKey().equalsIgnoreCase("India"))   //check for all the countries you want similarly
     key2.bindSelectedKey(<correspondingEnumType>);

For this to work, you will need to create a Enumeration Type for the states, say IndianStates having all the states you need. Create a context attribute of this enumeration type. Then, set the selectedKey property of your second DDBK to this context attribute.

This should work.

Hope this helps!

Regards

Kishan

Former Member
0 Kudos

Hi chandranna,

Can you please eloborate the answer.

I was confused with "key2.bindSelectedKey(<correspondingEnumType>);" , corresponding enumeration type in the sense name of simply type?and also with the context.can you please explain with an example.

Thanks in Advance.