cancel
Showing results for 
Search instead for 
Did you mean: 

Finding a model node in runtime

Former Member
0 Kudos

Hi, I'm presently migrating a old application to webdynpro.

In that application, I have a FieldDescriptor, which has the information of which table to search in order to find the info to be displayed.

Concretely I have:

A class called BapiInfoField. This class has an attribute which is the name of a table. I need to retrieve the node associated to that table.

To resolve this, I thought about making a mapping between the old table name and the new one compatible to webdynpro.

On the other hand, I don't know how to fetch an node at runtime in webdynpro. The only way I do usually, is by using the "wdContect.node*" way. I know how to fetch elements in a node dynamically, but not the node itself.

I also found a function called "getChildNode(String arg0, int arg1)" in the wdContext class. Unfortunately, the function is undocumented.

If there's no appropriate getter function in webdynpro for my problem, I'll resolve by making a mapping between the string of the old table name, and a Method Object linked to the proper "node*" method.

Anyone has any suggestions?

Thanks in advance,

Alexis

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Brrr...

I do not understand your requirements completely, but can provide some hints regarding getting nodes information at runtime.

First, you are misinformed: getChildNode is documented. First parameter is node name, second is index of parent element of subnode (i.e. index within "this" node).

Next, there are 2 different situations: you need only meta-information or you need physical data.

For first case:


  void traverse(final IWDNodeInfo parent)
  {
  	for (final Iterator i = parent.iterateChildren(); i.hasNext(); )
  	{
  		final IWDNodeInfo child = (IWDNodeInfo)i.next();
  		traverse( child );
  	}
  }
  traverse( wdContext.getNodeInfo() );

For second case:


  void traverse(final IWDNodeElement parent)
  {
  	final IWDNode     nParent   = parent.node();
  	final IWDNodeInfo niParent  = nParent.getNodeInfo();
  	final int         idxParent = parent.index();
  	for (final Iterator i = niParent.iterateChildren(); i.hasNext(); )
  	{
  		final IWDNodeInfo child = (IWDNodeInfo)i.next();
  		traverse( nParent.getChildNode( child.getName(), idxParent ) );
  	}
  }
  
  void traverse(final IWDNode parent)
  {
  	for (int i = parent.size() - 1; i>= 0; i--)
  	{

  		final IWDNodeElement element = parent.getElementAt( i );
                /* Workaround for singleton nodes */
                /* parent.setLeadSelection( i ) */
  		traverse( element );  
  	}
  }
  
  traverse( wdContext.currentContextElement() );

Second case is quite "interesting": first, it will fails for singleton nodes with cardinality 0..n or 1..n (see commented workaround); second, it quite resource-consuming, namely, invokes all supply functions and populating all elements during traverse.

Hope this will serve you as good starting point

VS

Former Member
0 Kudos

Hi,

Yes, I guess I talked too rapidly. I found the documentation of the getChildNode method before seeing your reply.

Thanks anyway for the traverse example, though I found a solution on my own.

I use:

wdContext.getChildNode( "TheNodeName", Node.LEAD_SELECTION );

Since my node is a singleton table, I guess this is fine.

Alexis