cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic context binding

Former Member
0 Kudos

Hi,

I have a View that adds dinamically one Image control on its view for every NodeElement present for a given node "A".

So, for example, if I have 5 elements in "A" I will have 5 Image(s).

Now, I want to bind the Source property of the Images to a calculated attribute hosted under another node "B".

Every single image has to show a different icon, based on the logic implemented in the getter method of the calculated attribute.

The code I wrote is this:

IViewBindingsElement curImageSource =                         
  wdContext.nodeB().createAndAddBElement();

IWDImage paramImage = view.createElement(
	  IWDImage.class);

paramImage.bindSource(
	  curImageSource.getAttributePointer("ImagePath").getAttributeInfo());

The problem is that when the calculated method is executed, the NodeElement reference passed to the method points always to the index-0 element (i.e. all the Images show the same icon, corresponding to the first "Node A" element).

Could someone help me with this?

Thank you,

Pietro

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Binding UI element properties to context node elements only works for data-driven UI elements like Table, RowRepeater etc, not for individual UI elements like in your example. What you can do, is to create a separate context attribute for each image and bind the "source" properties of the images to these attributes.

Former Member
0 Kudos

Thanks both of you,

at least now I know that what I'm trying to do it isn't possible...

Guess I'll have to put the logic of the calculated attributes somewhere else 😕

Thank you again,

Pietro

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Pietro,

You can access elements of node B by passing the index :

wdContext.node..getnode..elementat(index);

make sure you are setting the correct path in the corresponding element.

Please post the complete code of the method for better understandin.

For second query: Yes you can bind same attribute to any number of UI elements but it will have the same value.

Regards

Deepak

Former Member
0 Kudos

Hi Deepak,

thank you for your answer.

What I'm trying to do is to see if it is possible to bind an Image's "source" property to an attribute.

This attribute is calculated because the image source must be determined from the value of another attribute.

The problem is that I have multiple Images.

So I have

Node "Images" (cardinality 0..n)

- IWDImage image

Node "ImageBindings" (cardinality 0..n)

- string imageSource, calculated attribute

I would like to bind every Image to the corrispondent imageSource. The "Images" and "ImageBindings" node will have the same number of Elements. The problem is that if I do the binding as I've written, all the Images result bound to the same "ImageBindings" node element, i.e. the one that has the LeadSelection.

I hope that this clearer.

Thank you,

Pietro

ps. I'm not posting the whole method because the rest of the code is meaningless for this issue.

Former Member
0 Kudos

Hi,

I think I have understood your query.

As the image is standalone UI in your view, it will always take the lead select element's attribute value of the binded attribute. In this case you need to create new attribute to bind instead of new element in the node.

your approach may be useful with slight modification in below scenario.

If the image is inside a table - i.e. table cell editor of a column. And the attribute binded is in the same node which is defined as Source node of the table.Then the attribute value will automatically be taken from corresponding element. if attribute binded is from another node then again it will take lead select element of that node.

please go through below link to know more about dynamic creation of UI.

http://help.sap.com/saphelp_dm40/helpdata/en/4f/07cf3dd28b5610e10000000a114084/frameset.htm

hope it clears your doubt.

Regards

Deepak

Former Member
0 Kudos

Does anyone knows if binding multiple UI elements to one calculated attribute is possible?

Thank you,

Pietro