cancel
Showing results for 
Search instead for 
Did you mean: 

List/Enumeration of Elements in a View (WD for Java)

Former Member
0 Kudos

Hello,

How do I get a complete list of all elements in a view at runtime?

I want to dynamically modify 30+ elements, but I don't want to have to code each of them. Is there a way to do this?

Thanks,

Martin

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Normally, you don't need this functionality. You should bind UI element properties to context attributes and set attribute values instead.

If you want to implement a generic traversal of the complete UI tree of a view, you can use reflection.

An algorithm to do this is contained in Chris Whealy's book "Inside Web Dynpro for Java".

Armin

Former Member
0 Kudos

Thanks Armin. Actually, I want to set the context binding dynamically, because I'm too lazy to edit each of the 60+ elements in the IDE, so I'm going to traverse the UI Element tree instead.

Thanks.

Former Member
0 Kudos

Martin,

Try something like this:


static interface IAction 
{
  abstract public void execute(IWDUIElement el);	
}
  
static class CollectElements implements IAction
{
  final private Map _result = new TreeMap();
  	
  public Map result() { return Collections.unmodifiableMap(_result); }
  	
  public void execute(final IWDUIElement el) 
  {
    _result.put( el.getId(), el );  	
  }
}
  
void traverse(final IWDView view, final IAction action)
{
  traverse( (IWDUIElementContainer)view.getRootElement(), action );
}
  
void traverse(final IWDUIElementContainer container, final IAction action)
{
  action.execute(container);
  for (final Iterator i = container.iterateChildren(); i.hasNext(); )
  {
    final IWDUIElement el = (IWDUIElement)i.next();
    if ( el instanceof IWDUIElementContainer )
      traverse( (IWDUIElementContainer)el, action );
    else
      action.execute( el );
  }
}

Sample:


final CollectElements selectAll = new CollectElements();
traverse(wdView, selectAll);
/* Now selectAll.result() contains id->element mapping */

This will not collect Table columns, or Tabs in TabStrib, however you can create "dispatching" IAction implementation, that delegates to some custom methods like traverse(IWDTable) or traverse(IWDTabStrip)

Valery Silaev

EPAM Systems

http://www.NetWeaverTeam.com

Former Member
0 Kudos

Hi Valery,

Thanks for the code. I have already written something that suits my needs, also covering Tabstrips and tabs, but your code is very nice.

Answers (1)

Answers (1)

Former Member
0 Kudos

Never mind. I see I can just traverse the tree by using the root IWDUIElementContainer. Would have been nice to get a list in one go. If you have a solution like that, I will reward points.