cancel
Showing results for 
Search instead for 
Did you mean: 

Help! Problem binding UI elements to Context elements

Former Member
0 Kudos

Description of problem:

I am dynamically populating my context. Then I dynamically build my UI and try to bind my UI elements to the context. However I only see the FIRST value of the context element.


Context structure:
MatrixData       1..1   Singleton
    Table        0..n   Non-singleton
        Row      0..n   Non-singleton
           Name    string attribute

In wdDoInit() I populate the context as follows:
  public void wdDoInit()
  {
	String [] sizeNames = new String [] {"Small", "Medium", "Large"};
	
	IMatrixDataNode matrixDataNode =  wdContext.nodeMatrixData();
	IMatrixDataElement matrixDataEl = matrixDataNode.currentMatrixDataElement();
	IContainerNode containerNode = matrixDataNode.nodeContainer();
	
	for(int fitIdx = 0; fitIdx < 3; fitIdx++)
	{
		for(int materialIdx = 0; materialIdx < 2; materialIdx++)
		{
			ITableNode tableNode = matrixDataNode.nodeTable();
			ITableElement tableEl = tableNode.createTableElement();
			tableNode.addElement(tableEl);
			IRowNode rowNode = tableEl.nodeRow();
			for(int sizeIdx = 0; sizeIdx < sizeNames.length; sizeIdx++)
			{
				IRowElement rowEl = rowNode.createRowElement();
				rowEl.setName(sizeNames[sizeIdx]);
				rowNode.addElement(rowEl);
			}
		}
	}
  }

In wdDoModifyView I do the following:


  public static void wdDoModifyView(IPrivateMatrixWithTransparentContainers2 wdThis, IPrivateMatrixWithTransparentContainers2.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
  {
    //@@begin wdDoModifyView
	IWDTransparentContainer mainContainer = (IWDTransparentContainer) view.getElement("DynamicTransparentContainer");
	mainContainer.destroyAllChildren();
	IWDLabel lbl = createLabel(view, "Lbl1");
	setMatrixHeadData(lbl, null);
	int currentTable = 0;
	int numRows = wdContext.getChildNode("MatrixData",0).getChildNode("Table", 0).getChildNode("Row", 0).size();
	int uniqueId = 0;
	mainContainer.addChild(lbl);
	for(int i = 0; i < numRows; i++)
	{
		// Get the node info for row i
		IWDNodeInfo nodeInfo = wdContext.getChildNode("MatrixData",0)
									.getChildNode("Table", 0)
									.getChildNode("Row",i)
									.getNodeInfo();
		// Get the AttributeInfo for attribute "Name"
		IWDAttributeInfo attrInfo = nodeInfo.getAttribute("Name");
		
		// Create a label and bind its text to the AttributeInfo
		lbl = createLabel(view, "Lbl_" + (++uniqueId));
		setMatrixHeadData(lbl, null);
		lbl.bindText(attrInfo);
		mainContainer.addChild(lbl);
	}
    //@@end
  }

The result of this code is:

Small

Small

Small

Why is this????

If, instead of Label.bindText I use Label.setText, then the result is:

Small

Medium

Large

- which is the correct result.

Why is bindText not working correctly?

Any help much appreciated,

Walter Kahn

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

I am not sure if i am understanding ur requirement.

As per ur requirement u r supposed to bind the attribute to the particular column and not to every row of that column

like "Table.Row"

Regards

Bharathwaj

Former Member
0 Kudos

The context nodes are just called "Table" and "Row". I specifically do NOT want to create a IWDTable element. I want to have multiple IWDInput elements, each one bound to a single context attribute: Row.Name

Walter

Former Member
0 Kudos

Hi,

when u bind a input field to an attribute which has more than one instance it will show the valuw which is lead selected.. and so when u bind all the UI elements to this attributes it will show the lead selected value only.

Former Member
0 Kudos

I understand this now. Do you have a suggestion for how I can achieve my aim?

Thanks,

Walter

Former Member
0 Kudos

I finally solved this problem by creating a unique NodeInfo object for every node.

If anyone is interested in exact details, contact me.

Former Member
0 Kudos

That would indeed be interesting (to see if it's correct Can you please post your solution here?

Armin

Former Member
0 Kudos

Hi Walter,

I also want to achieve the same. Please send your sample code to me at shubham.tripathi@gmail.com or post your code here.

Regards,

Shubham

Former Member
0 Kudos

The bindText() is working correctly. If you bind a UI element property to a context attribute, then the value is given by the path from the context root, following the lead selection, to the node containing the attribute.

It's not clear to me what you want to achieve with the given code. You are referring to a node "Container" that is not shown in your context structure.

Can you describe your use case in more detail?

Armin

Former Member
0 Kudos

Sorry if my explanation was not clear. Here is what I am attempting to do:

I want to construct a number of "Tables".

Each "Table" has n "Rows".

Each "Row" has only one attribute - "Name".

In the example I posted I built 6 tables, each with 3 rows. I tried to get the first Table, loop through the Rows, and bind a new Label to the "Name" attribute of each Row.


// Get the node info for row i
IWDNodeInfo nodeInfo = wdContext.getChildNode("MatrixData",0)
							.getChildNode("Table", 0)
							.getChildNode("Row",i)
							.getNodeInfo();
// Get the AttributeInfo for attribute "Name"
IWDAttributeInfo attrInfo = nodeInfo.getAttribute("Name");

and then use that IWDAttributeInfo in the bindText method.

Even though I use getChildNode("Row", i), and i loops from 0 - 3, I only ever see the value of the first "Name" attribute - "Small", repeated 3 times ("Small", "Small", "Small"). I expect to see: "Small", "Medium", "Large".

I know that I could use setText here, but in the project I am working on, I actually need these to be input fields, and I want to be able to update multiple tables/rows simultaneously, so I need to be able to bind to the value of every row in every table.

I hope that this explains more clearly what I am trying to do.

Walter

Former Member
0 Kudos

Hi,

Set text will set the value of the label with the attrinfo for evry iteration of the loop..

But when we use bind we are saying that it is linked to the attrinfo..

So whatever is there in attrinfo is displayed in all the labels..

Regards

Bharathwaj