on 09-17-2009 3:22 PM
Hi All,
I want to create n number of tables dynamically. I tried to create nodes for each table dynamically but it gives me exception
com.sap.tc.webdynpro.progmodel.context.ContextException: Node(Result): value node is created without a reference
Can any one please help to create tables dynamically.
Thanks in advance.
Regards,
Jude
First you have to create n context nodes used as data source nodes and their attributes. Assuming all the nodes have the same structure:
for (int i = 0; i < n; ++i)
{
IWDNodeInfo nodeInfo = createValueNode("TableDataSource" + i);
nodeInfo.addAttribute("attributeName1", "ddic:com.sap.dictionary.string");
nodeInfo.addAttribute("attributeName2", "ddic:com.sap.dictionary.boolean");
/* etc */
}
IWDNodeInfo createValueNode(String nodeName)
{
return wdContext.getNodeInfo().addChild(
nodeName,
null, /* value node */
true, /* singleton */
false, true, /* cardinality 0:n */
false, true /* selection 0:n */
false, /* initialize lead-selection */
null, null, null
);
}
This should happen for example in an event handler or whenever you need to rebuild the data source nodes.
In wdDoModifyView() the Table and its components should be created:
static void wdDoModifyView(...)
{
if ( rebuildTables )
{
IWDUIElementContainer tableContainer = (IWDUIElementContainer) view.getElement("id_of_container");
tableContainer.destroyAllChildren();
for (int i = 0; i < n; ++i)
{
IWDTable table = (IWDTable) view.createElement(IWDTable.class, "Table" + i);
IWDNodeInfo dataSourceNodeInfo = wdContext.getNodeInfo().getChild("TableDataSource" + i);
table.bindDataSource(dataSourceNodeInfo);
addColumn(table, dataSourceNodeInfo, "attributeName1", IWDInputField.class);
addColumn(table, dataSourceNodeInfo, "attributeName2", IWDCheckBox.class);
tableContainer.addChild(table);
/* TODO: add layout data to table according to container's layout */
}
}
}
static void addColumn(IWDTable table, IWDNodeInfo dataSourceNode, String attributeName, Class editorType)
{
IWDTableColumn column = (IWDTableColumn) table.getView().createElement(IWDTableColumn.class, null);
table.addColumn(column);
if (editorType == IWDInputField.class)
{
IWDInputField editor = (IWDInputField) table.getView().createElement(IWDInputField.class, null);
editor.bindValue(dataSourceNode.getAttribute(attributeName);
}
else if (editorType == IWDCheckBox.class)
{
IWDCheckBoxeditor = (IWDCheckBox) table.getView().createElement(IWDCheckBox.class, null);
editor.bindChecked(dataSourceNode.getAttribute(attributeName);
}
/* etc */
}
You could also determine the cell editor type automatically from the attribute type instead of passing it explicitly. For assigning actions to the cell editor further coding is needed but this should give you an idea.
Armin
Code-tags seem to be broken at the moment?
Edited by: Armin Reichert on Sep 17, 2009 7:18 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jude,
Post the code that you used to create nodes for each table dynamically. I might have a look and let you know if I find any issues.
Regards,
Gopal.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
25 | |
12 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.