cancel
Showing results for 
Search instead for 
Did you mean: 

Recursive Tree with model nodes: how to add elements

former_member190457
Contributor
0 Kudos

Hi developers,

In my app I have a recursive WDJ tree based on model nodes.

Questions:

1. how can I get the currently selected element? The classic

wdContext.currentTreeRootElement();

always returns the root element of course, how should I go on?

2. how can I add elements to a node (remember here I have recursive node)?

Should I create a model object and then add it to the node retrieved as per question 1?


previouslyRetrievedNode.add(myNewlyCreateModelObject);

Any pointer or suggestion would be greatly valued

Thanks in advance

Vincenzo

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

1. current selection

http://help.sap.com/javadocs/nwce/current/wdr/com.sap.wdr/com/sap/tc/webdynpro/progmodel/api/IWDNode...

2. Say you have the following context structure:


Items (node)
+ Children (recursive node -> Item)

Then you can a child to a tree node like this:


IITemsElement item = ...;
IITemsElement child = item.nodeChildren().createAndAddItemsElement();

Armin

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi

If your context structure is as below:

TreeRoot

---> ChildTree (recursive of type TreeRoot)

For example if TestModelNode is the source model node to populate the tree structure:

And in your model node -

elements having value in an attribute Value1 - you need to popualte these values as ROOT elements

elements having value in attribute Value2 - you need to populate these values as childs

Then to populate the root nodes:

addChildNodes(IPrivateTestView.ITreeRootNode node,String parentId)
{
  for(int i=0;i<wdContext.nodeTestModelNode().size(),i++)
  {  
      if("ROOT".equalsIgnoreCase(parentId) && !"".equalsIgnoreCase(wdContext.nodeTestModelNode().get
       TestModelNodeElementAt(i).getValue1()))
      {
       
        newTreeRootElement = node.createTreeRootElement();
        newTreeRootElement.setParentId(wdContext.nodeTestModelNode().getTestModelNodeElementAt(i).getValue1());
        newTreeRootElement.setOtherAtt1();
        newTreeRootElement.setOtherAtt2();..etc
        wdContext.nodeTreeRoot().addElement(newTreeRootElement);
       if( checkIfChidsExist(wdContext.nodeTestModelNode().getTestModelNodeElementAt(i).getValue1())==true)
       addChildNodes(newTreeRootElement.nodeChildTreeNode(),wdContext.nodeTestModelNode().getTestModelNodeElementAt
       (i).getValue1());        
      }
      else
      {
        newTreeRootElement = node.createTreeRootElement();
        newTreeRootElement.setParentId(wdContext.nodeTestModelNode().getTestModelNodeElementAt(i).getValue2());
        newTreeRootElement.setOtherAtt1();
        newTreeRootElement.setOtherAtt2();..etc
        wdContext.nodeTreeRoot().addElement(newTreeRootElement);
       if( checkIfChidsExist(wdContext.nodeTestModelNode().getTestModelNodeElementAt(i).getValue2())==true)
       addChildNodes(newTreeRootElement.nodeChildTreeNode(),wdContext.nodeTestModelNode().getTestModelNodeElementAt
       (i).getValue2());  
      }
}
}


public boolean checkIfChildsExists(String value1)
{
  for(int i=0;i<wdContext.nodeTestModelNode().size(),i++)
  {
   if(value1.equalsIgnoreCase(wdContext.nodeTestModelNode().getTestModelNodeElementAt(i).getValue2()))
    {
      return true;
    }
  }
   return false;
}

Regards,

Charan

former_member185879
Active Contributor
0 Kudos

Hello All,

I have added some values in Recursive Node. Now i want to export in an excel on cliking of a button in webdynpro. I have a export code, but i need a help on how to read recursive node elements for that parent node.

Regards

SM Nizamudeen

siarhei_pisarenka3
Active Contributor
0 Kudos

Hi Vincenzo

>1. how can I get the currently selected element?

Recursive node is always Non Singleton. So an access to child elements on a specific level is performed via nearest parent element. In the same manner as working with any other non-singleton node. The only specific thing is the following: child node name is not the same as root recursive node name:

parentElement.nodeChildren().currentRecNodeElement();

>2. how can I add elements to a node (remember here I have recursive node)?

In the same manner as working with any non-singleton node:

parentElement.nodeChildren().createRecNodeElement();

BR, Sergei

Former Member
0 Kudos

HI,

You should add elements to your node in a loop like

for(int i=0;i<5;i++)

{

Iprivateview.IrootElement ele = wdContext.nodeRoot().createRootElement();

ele.setA("abc");

wdContext.nodeRoot().addElement(ele);

}

This will create five elements for root node.

Regards

Raghu

Former Member
0 Kudos

Hi Vincenzo,

read this tutorial

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/user-interface-tec...

A code example "addElements" is provided on page 19. But the document also explains the general structure of recursive context nodes.

Or try this help.sap.com page: http://help.sap.com/saphelp_nw04/helpdata/en/16/1ec1814e566f4baf943c53ccf48552/content.htm for copy&paste wdInit code you can use directly ...

Hope it helps,

Jan