cancel
Showing results for 
Search instead for 
Did you mean: 

Create ' n' no of Tables Dynamically

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

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

Former Member
0 Kudos

Its just my browser or the "" is not working anymore? I've seen also some of my old posts with the code part all messed up, and im unable to edit them anymore in order to correct them.

Any hint on this?

Regards

Julio H

Former Member
0 Kudos

Seems to be a bug in the forum software, the code-tags appear unchanged in the HTML source.

Armin

Former Member
0 Kudos

Hi All,

Sorry for the late reply....I created nodes for table dynamically.

Thanks for all your posts.

Regards,

Jude

Former Member
0 Kudos

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.