I would like to share my experience with Tree control in WebDynpro and recursive context nodes.
The first thing worth noticing is that Tree control can exist in two flavours. One is when the tree structure is known at design time, and the second when the tree structure is dynamic. In my weblog I focus on the dynamic flavour.
Dynamicly structured tree is generated somehow automatically based on context structure. I.e. one context node corresponds to one tree node, and descendant context nodes are visualized as descendant tree nodes. The simplest way to provide such a context structure is to use recursive context node and build context structure dynamically. This approach is also correct, because the data one can store have flat (table-like) structure, not a tree-like structure.
The weblog covers
- converting flat table-like structure with references to parent fields to a tree structure based on recursive context node
- using the Tree control based on the recursive context
- checking which node is selected in the Tree
The first thing to do is to create proper context structure in the controller.
And that’s it. 🙂 Use InputField’s for table editors, add some simple methods to add/remove rows in the flat structure and you’re off to run a simple example. My version for such simple data :
provides a tree that looks like this :
Now, how to check which node is clicked ?
It is relatively simple – selecting a node in the tree updates lead selection on all nodes from the root to the selected node, including it, and leaves deeper nodes with empty lead selection. If you recursively analyze the tree from the root node and follow the lead selection, you will end up with the selected node. I leave the implementation to you as an excersise. 🙂