cancel
Showing results for 
Search instead for 
Did you mean: 

Iterate Child Nodes

Former Member
0 Kudos

Hello,

I'm constructing a Value node (X)that is comprised of multiple model nodes inside (1,2,3..). I would like to iterate over X and to return me nodes 1 2 3... The way I constructed this node is as follows:

wdContext.nodeA.node1.bind(OBJ1); //Is this correct?

wdContext.nodeA.node2.bind(OBJ2);

.

.

.

I verified that:

wdContext.nodeA.node1.currentNode1Element()

returns a valid element, but when I call wdContext.nodeA.iterateChildNodes() the iter.hasNext() is always false. Do I have to set any properties on the parent/child nodes for this to work?

Help is much appreciated.

Dustin

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Dustin,

Here is your error

Iterator iter = wdContext.nodeDetailInstructions().iterateChildNodes();

Buddy, you are calling non-API method (from com.sap.tc.webdynpro.progmodel.context.Node), and what it does is unknown for me

Instead call

Iterator iter = wdContext.nodeDetailInstructions().getNodeInfo().iterateChildren();

WBR,

VS

Former Member
0 Kudos

Hello Valery,

This method the iter.next() will return a IWDNodeInfo object. I need the actual node object so I can get the current element out of it, not the node info. This will work for me because from this I could get the node name, and if I keep an index I will be able to get the current node out of the parent node. This seems a really round about way when I should just be able to iterate through the parent node and get node objects back. The following logic will work...it is just ugly.

[code]

Iterator iter = wdContext.nodeDetailInstructions().getNodeInfo().iterateChildren();

while(iter.hasNext()){

IWDNodeInfo nodeInfo = (IWDNodeInfo)iter.next();

IWDNode currentNode = wdContext.nodeDetailInstructions().getChildNode(nodeInfo.getName(), 0);

//Do stuff with currentNode

}

[\code]

In effect, but like I said...it is not elegant at all.

Former Member
0 Kudos

Hi Dustin,

As suggested by Armin, it shd definitely work. Otherwise really something strange is happening. I want to know a couple of things:

1)Have you created the childnodes declaratively or programatically???

2)If you have created the childnodes programatically, then have you made sure that you iterate only after the child nodes are created???(I know u would definitely made sure of this... But just want to verify... 'coz sometimes one does such silly mistakes and then simple things dont work.).

3) if u have created the child nodes programatically, where have you created it and where are you iterating this??

Otherwise, its really strange...I think the code that u have written shd work!

Regards,

Vishnu Prasad Hegde

Former Member
0 Kudos

Dustin,

Could you provide real code instead of halfly-inlined statements. Otherwise it hard to predict what is wrong.

For example, whether

<i>I call wdContext.nodeA.iterateChildNodes() the iter.hasNext() is always false</i>

equals to following


for (final Iterator i = wdContext.nodeA().getNodeInfo().iterateChildren(); i.hasNext() )
{
  final IWDNodeInfo niChild = (IWDNodeInfo)i.next();
}

If so, then realy something strange happens...

Valery

Former Member
0 Kudos

Hi Valery,

First I'd just like to thank you for helping me out.

Here is a more complete code snippet.


Iterator iter = wdContext.nodeDetailInstructions().iterateChildNodes();
    
    while(iter.hasNext()){
    	IWDNode currentNode = (IWDNode)iter.next();
        //Do stuff with currentNode
        .
        .
}

nodeDetailInstructions is filled multiple statements like:


wdContext.nodeDetailInstructions.nodeInner1.bind(innerobj1);
wdContext.nodeDetailInstructions.nodeInner2.bind(innerobj2);
.
.
.

Dustin

Message was edited by: Dustin Gronso