Skip to Content

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.


image


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 :


image

provides a tree that looks like this :


image

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. 🙂

To report this post you need to login first.

8 Comments

You must be Logged on to comment or reply to a post.

  1. Valery Silaev
    Ok, now small challenge for you (to make your article at least a bit valuable besidse reproducing NW UI Element Library Reference)
    1. You have a recursive node OrgUnit.
    2. Also right below recursive OrgUnit node you have non-singleton 0..n node Employees (isSelected->boolean, FullName->string)
    Try to create master->details UI where “master” displayed as tree of OrgUnit-s, and details is table of Employees per selected OrgUnit that allows you to select 0..m employees.

    You’ll be surprised how things become more interesting — there are some pitfalls with recursive nodes 😉

    VS

    (0) 
    1. Hi Valery,

      Actually i did not reproduce the UI reference example. The example is a part of my own project – organization’s structure editor.

      I did not try to reproduce the problem you speak about. More, I would be really afraid to put another node in recrusive tree structure. I’ve got a strange feeling, that it would mess-up things a bit. 🙂

      In my application the employess are in separate Context node, and they have an value attribute containing the id of assigned node in organization’s structure. If I would try to keep employees grouped by the occupation in child node of “OrgStruct” node i would render an unbrowseable data structure for the employees. Keeping them in separate flat structure allows me to work on the list easily.

      If you have some experience with the issue you posted, maybe you could post a blog about it ?


      regards
      Marcin

      (0) 
      1. Valery Silaev
        First, I has no intent to offence you — my pardons if it sounds so.

        About own blog post — yep, probably shortly.

        About challenge itself. There is one “feature” when using recursive nodes — if you have non-recursive child of recursive node it is not preselected automatically for nested levels. Therefor having tree for recursion and table for non-recursive child will not work out of the box.

        The workaround we found is to have top-level node with same attributes, track tree selection and dynamically copy elements back and force.

        Probably someone knows better way…

        VS

        (0) 
        1. Harsh Chawla
          Hi Marcin,
              A well presented blog, recommended to all. Fun to try out:).
          Regards,
          Harsh

          PS: Valery, I’m a bit confused about your last comment.
          “if you have non-recursive child of recursive node it is not preselected automatically for nested levels.”
          Your comment seems to indicate that it can be done manually. So is there a way to select it manually for recursion? or is it a limitation?
          Usefull info either way, (I wasn’t aware of this.)

          (0) 
        2. Harsh Chawla
          Hi Marcin,
              A well presented blog, recommended to all. Fun to try out:).
          Regards,
          Harsh

          PS: Valery, I’m a bit confused about your last comment.
          “if you have non-recursive child of recursive node it is not preselected automatically for nested levels.”
          Your comment seems to indicate that it can be done manually. So is there a way to select it manually for recursion? or is it a limitation?
          Usefull info either way, (I wasn’t aware of this.)

          (0) 
        3. Harsh Chawla
          Hi Marcin,
              A well presented blog, recommended to all. Fun to try out:).
          Regards,
          Harsh

          PS: Valery, I’m a bit confused about your last comment.
          “if you have non-recursive child of recursive node it is not preselected automatically for nested levels.”
          Your comment seems to indicate that it can be done manually. So is there a way to select it manually for recursion? or is it a limitation?
          Usefull info either way:).. (I wasn’t aware of this.)

          (0) 
          1. Valery Silaev
            Yes, it can (and should) be done manually.
            I prefer to name it feauture or specific behavior rather then limitation.
            In my own blog I’ve started a serie of posts regarding TreeTable control and recursive nodes (as far as this control may be bound to only this type of nodes). In my next post I will describe this problem as well as provide a working example how to manage it.

            VS

            P.S. Marcin, my pardons for shameless plug 😉

            (0) 

Leave a Reply