on 07-15-2008 4:14 PM
Hello,
I am creating a SD Product Hierarchy using Web Dynpro Tree. The Requirement is : No of Nodes & the Depth of the hierarchy is unknown at design time. All the details are coming from the RFC.
So, How can I build a tree dynamically reflecting the dynamic depth & no.of nodes?. I have the "Creating WebDynpro Tree" tutorial with me, But unable to understand dynamic tree creation.
If somebody know how-to do it, Please let me know.
Thanks,
Sunita.
The tree structure is created by context node elements and their recursive child nodes.
Let your context structure look like
Products (node, 0:n)
-- id (string)
-- Parts (recursive node -> Products)
Say you have a product p . Then you add parts to this product by adding elements to the "Parts" subnode of p which again is of type "Products" (recursion):
IProductsElement p = ...;
/* add parts to product p: */
IProductsElement part1 = p.nodeParts().createAndAddProductsElement();
part1.setId("p/1");
IProductsElement part2 = p.nodeParts().createAndAddProductsElement();
part2.setId("p/2");
To add further sub-parts, use the same functionality e.g. for part2:
IProductsElement subpart1OfPart2 = part2.nodeParts().createAndAddProductsElement();
subpart1OfPart2.setId("p/2/1");
Hope you get the idea.
Armin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Monalisa,
Thanks for pointing out to a nice blog. If the no. of nodes is unknown, its easy. But how to handle the levels / depth of the tree dynamically.
In this blog he assumed there are 3 levels at designtime. What if, there are unknown levels and it cant be determined at design time.
Does anybody faced this scenario. Please help,
Thanks,
Sunita.
Hi Sunita,
The number of nodes determines the depth/levels of tree.
You can modify the same code, which creates 3 levels in the tree to create dynamic tree.
// create first level in the tree
IPrivate<ViewName>.I<Tree Node>Element rootelement = wdContext.create<Tree Node>Element();
rootelement.setText("<Text>");
wdContext.node<Tree Node>().addElement(rootelement);
//create n levels in the tree
for(int i=1;i<n;i++)
{
IPrivate<ViewName>.I<Tree Node>Element childelement
= rootelement.node<RecursiveNode>().create<Tree Node>Element();
rootelement.node<RecursiveNode>().addElement(childelement);
childelement.setText("<Text>");
//change parent element
rootelement = childelement;
}
Hope it helps!
>
> Hi Sunita,
>
> The number of nodes determines the depth/levels of tree.
> You can modify the same code, which creates 3 levels in the tree to create dynamic tree.
> // create first level in the tree
> IPrivate<ViewName>.I<Tree Node>Element rootelement = wdContext.create<Tree Node>Element();
> rootelement.setText("<Text>");
> wdContext.node<Tree Node>().addElement(rootelement);
>
> //create n levels in the tree
> for(int i=1;i<n;i++)
> {
>
> IPrivate<ViewName>.I<Tree Node>Element childelement
> = rootelement.node<RecursiveNode>().create<Tree Node>Element();
> rootelement.node<RecursiveNode>().addElement(childelement);
> childelement.setText("<Text>");
> //change parent element
> rootelement = childelement;>
> }
> Hope it helps!
Monalisa,
This Sample looks very promising. I havent tried it yet. I will update the thread once I try. BTW, Could you please explain me the last line of code "rootelement = childelement".
Appreciate your help. Yes, its truly helpful. Thanks.
Sunita.
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.