on 07-11-2006 9:55 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.