cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Binding of Node to DropdownBYKey

Former Member
0 Kudos

Hi Colleagues,

I am new to WebDynpro.

I am facing an issue with "DropDownByKey" UI Element.

The scnario is:

1) There are 15 number of "DropDownByKey" UI Elements to be displayed on a page with the same data (time intervals).

One approach to achieve this would be:

1) Create a 15 attributes of simple data type and enter options in

enumerations.

2) Now bind each of these simple data types to all the 15 DropdownByKey elements.

The second approach could be:

1) Create a node with attribute type string.

2) Write functionality to add values to this attribute.

3) Create instances of Node.Attribute.

4) Bind these instances to individual 15 DropdownBykeys elements.

Please tell me which one of the two approaches would be better or if there is any other better approach.

In case, if the second appraoch is better, how to achieve this?

Thanks & Regards,

Ankit.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Create one SimpleType in Dictionaries with time data .

Then use Dynamic programming to achieve your need

in wdDomodifyView() method, write following code

wdContext.getContext().reset(false);

IWDTransparentContainer tc= (IWDTransparentContainer)view.getElement("RootUIElementContainer");

tc.destroyAllChildren();

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

{

wdContext.getNodeInfo.addAttribute("attr"+i,"<SimpleTypePackage>.<SimpleTypeName> ");

}

for(int k=0;k<15;k++)

{

IWDDropDownByKey ddk=(IWDDropDownByKey)view.createElement(IWDDropDownByKey.class,"ddk");

ddk.bindSelectedKey("attr"+k);

tc.addChild(ddk);

}

Regards

LN

Answers (5)

Answers (5)

Former Member
0 Kudos

Thank you all.

Your replies were really helpful in resolving the issue.

The question has been answered now.

Best Regards,

Ankit.

Former Member
0 Kudos

Hi Ankit,

check these threads :[thread1|;

[thread2|;

hpe it hlps

Regards

Khushboo

Former Member
0 Kudos

Hi,

follow below steps,

1.create one simple type which holds required values

2.create 15 value attributes of type simple type.

3.bind with DropDownByKey.

it is easy way to achieve your requirement.

Regards,

ramesh.

Former Member
0 Kudos

I suggest first option because we may select different value in each dropdown.

If we maintain only one attribute to all dropdown elements selected value will be same for all dropdowns

Let me know if you need more clarifications

Thanks

Former Member
0 Kudos

Hi Tatayya,

It means that I should create 15 separate attributes for 15 different UI Elements of same type (DropDownByKey).

Is there any way to create instances of a Ui Context node and attach these instances to UI Elemnts at runtime?

Thanks & Regards,

Ankit.

srinivas_sistu
Active Contributor
0 Kudos

Hi,

Below way you can set values to a dropdown by key without using enumaration(your 2nd approcah) .

/*Setting the Dropdown/

IWDAttributeInfo info_propno =wdContext.nodeVn_From1NoOfPropsDropDown().getNodeInfo().getAttribute("Va_F1noOfProps");

ISimpleTypeModifiable mod_propno =

info_propno.getModifiableSimpleType();

IModifiableSimpleValueSet svs_propno =

mod_propno.getSVServices().getModifiableSimpleValueSet();

String strcount=null;

for (int count = 0;count<

form1List.size();//wdContext.currentVn_FormDetailsElement().getVa_Form1List().size();

count++) {

strcount=""(count1);

svs_propno.put(strcount,strcount);

strcount="";

}

/** End of Setting the Dropdown*/

Note : If you use a dropdown element and if you dont assign a context variable to it, you will get a null pointer exception.

Regards,

Srinivas.

Former Member
0 Kudos

Hi Srinivas,

Thanks for your quick response.

By this way:

-


if I assign a Context Element to 15 DropDownByKeys, and select one value for a drop down box

-


then, the rest of the drop down boxes also reflects the same value.

Please let me know how to resolve this issue.

Thanks & Regards,

Ankit.

srinivas_sistu
Active Contributor
0 Kudos

Hi,

You can achieve it.

if you can see the code, in the for loop for setting the key value pair,

we are doing a

svs.put(key,vlaue);

Now make this dynamic like

String reqKey=null;

String reqVal=null;

If(requirement1)

{

reqKey="requirement1 keys";

reqVal="requirement1 values";

}

If(requirement2)

{

reqKey="requirement2 keys";

reqVal="requirement2 values";

}

Now

svs.put(reqKey,reqVal);

Regards,

Srinivas.

Former Member
0 Kudos

Hi Srinivas,

Thanks for your valuable suggestions.

The requirement over here is to:

1) Create 15 instances of attributes containing the same values.

2) And then assign one by one each of these instances to each of the 15 UI Elements.

Please let me know how to do it (Dynamically binding the attribute instances to the DropdownByKey UI Elements)?

Thanks & Regards,

Ankit.

vmadhuvarshi_
Contributor
0 Kudos

Ankit,

Here is how you can achieve what you want to do.


public static void wdDoModifyView(IPrivateMulti_DropDownCompView wdThis, IPrivateMulti_DropDownCompView.IContextNode wdContext, 
com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
  {
    //@@begin wdDoModifyView
	  if(firstTime)
	  {
		  for(int i=1; i<=15; i++)
		  {
			  IWDDropDownByKey theDropDown = (IWDDropDownByKey) view.getElement("DropDownByKey"+i);
			  IWDAttributeInfo att1 = wdContext.nodeDDNode().getNodeInfo().addAttribute("DD"+i+"Data", 
                                                            "ddic:com.sap.demo.multi_dropdowns.DataValue");
			  theDropDown.bindSelectedKey(att1);
		  }
	  }
    //@@end
  }

The assumption here are

1. Your DropDownByKey element ids are DropDownByKey1 through DropDownByKey15.

2. You have an independent node DDNode with cardinality 0..n

3. You have one simple type DataValue with required enumeration created under path com.sap.demo.multi_dropdowns

This works fine and different values can be selected for separate DropDownByKey elements.

Having said this, I am not sure why you want to do this dynamically when this can be achieved easily by creating 15 attributes of a simple type 'DataValue' and binding them to your DropDownByKey elements at design time. I hope you are not getting confused among 15 attributes and 15 elements as binding an element to DropDownByKey is not possible (as far as I know).

It is better to construct as much of the view layout as possible at design time to keep things simple for you and later for people supporting the application.

Anyway, you have both the options now :-). Take your pick.

Hope this helps.

Vishwas.