cancel
Showing results for 
Search instead for 
Did you mean: 

Adding field to context node programatically

Former Member
0 Kudos

Hi,

I'm preparing table application.

a table's columns number is dynamic, so i must add field to context node to bind it to table.

Is it possible?If possible, how?

Thanks

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Dear,

You can use the following code to create a value node & then add value attributes

to this node using the following code :


 
// Get the metadata object for the context root node
IWDNodeInfo rootNodeInfo = wdContext.getNodeInfo();

// Create a metadata object to describe a new independent node
// called "YourNode"
IWDNodeInfo yourNodeInfo =
rootNodeInfo
.addChild("YourNode", // Name
null, // Structure reference
true, // Is singleton?
false, true, // Cardinality
false, false, // Selection cardinality
true, // Initialise lead selection?
null, // Datatype
null, // Supplier function
null); // Disposer function

// Add the attribute metadata to the new node info object
yourNodeInfo.addAttribute("Attribute1","ddic:com.sap.dictionary.integer");
yourNodeInfo.addAttribute("Attribute2","ddic:com.sap.dictionary.string");
yourNodeInfo.addAttribute("Attribute3","ddic:com.sap.dictionary.date");
yourNodeInfo.addAttribute("Attribute4","ddic:com.sap.dictionary.string");

In the above a code node "YourNode" is created dynamically and then the attributes

"Attribute1","Attribute2","Attribute3", "Attribute4" are added .

Warm Regards

Upendra Agrawal

Former Member
0 Kudos

Hi Upendra,

Thanks a lot for your answer.

If new node created at controller, how can it be linked to views?

Thanks.

Former Member
0 Kudos

Upendra,

Another thing is,

How can it be bind to a table programatically.

At that time must table be created programatically in a view?

Thanks.

0 Kudos

an example:

create Context node

public void wdDoInit()

{

//@@begin wdDoInit()

//Node

IWDNodeInfo nodeInfo = wdContext.getNodeInfo();

IWDNodeInfo mynode =nodeInfo.addChild("nodeName", null, true, false, true, false, false, true, null, null, null);

mynode.addAttribute("attributeName", "ddic:com.sap.dictionary.string");

IWDNode node = wdContext.getChildNode("nodeName", 0);

//element

IWDNodeElement element = node.createElement();

element.setAttributeValue("attributeName", "Value1");

node.addElement(element);

//@@end

}

binding:

public static void wdDoModifyView(IPrivateContextdinView wdThis, IPrivateContextdinView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)

{

//@@begin wdDoModifyView

if (firstTime){

IWDTransparentContainer rootElement = (IWDTransparentContainer) view.getRootElement();

IWDTable myTable = (IWDTable) view.createElement(IWDTable.class,"MyTable");

myTable.bindDataSource(wdContext.getChildNode("nodeName", 0).getNodeInfo());

IWDTableColumn col1 = (IWDTableColumn)view.createElement(IWDTableColumn.class,"col1");

IWDTextView txtw1 =(IWDTextView)view.createElement(IWDTextView.class,"txtw1");

txtw1.bindText("nodeName.attributeName");

IWDTableCellEditor cled1 = txtw1;

col1.setTableCellEditor(cled1);

myTable.addColumn(col1);

myTable.setVisibleRowCount(5);

rootElement.addChild(myTable);

}

//@@end

}

enjoy yourself : )

Former Member
0 Kudos

Hi Luca,

It gets error below

WDRuntimeException: DataSource attribute of table not valid

Error occure line of code below

myTable.bindDataSource(wdContext.getChildNode("nodeName", 0).getNodeInfo());

Edited by: cml_bzl on Oct 17, 2009 10:07 PM