cancel
Showing results for 
Search instead for 
Did you mean: 

Creating Nodes and Binding them at runtime

tom_cole3
Explorer
0 Kudos

I have a requirement to create a dynamic table. The overall layout would be something like:


Sequence    Department    Plant 1     Plant 2    Plant 3    Plant 4
10          Sales         Tom         Jeff       Fred       Barney
20          Marketing     Tom         Dave       Alex       Barney

...

The issue is this, the number and names of the "Plants" aren't know until runtime. In addition each name I show in the example above would actually be a dropdown list of available names for the given plant/department. So Plant 1 / Sales would have a different drop down list then Plant 1 / Marketing, etc. Each dropdown listed under each plant would be unique to that plant AND department. In theory there could be 50 drop downs, all of them with a completely unique list of people to choose from.

I have a context node named "Approvers" that currently has only Sequence and Department as attributes. I figured I was going to have to create a non-singleton child node for each "Plant" under that node, create the table column (assigning the name of the plant to the column header) with a drop down by index as the cell editor and bind it to this new non-singleton node.

1. Does this sound like the proper method to acheive this goal?

2. If so I need help creating these dynamic nodes. I have created dynamic attributes for a node before, but never have I had to create nodes, and non-singletons at that.

Any help would be greatly appreciated. My head is spinning

Accepted Solutions (1)

Accepted Solutions (1)

siarhei_pisarenka3
Active Contributor
0 Kudos

Hi Tom

Look at the blog: [Dynamic UI Generation: Table displayed in row wise (horizontally)|https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/16125] [original link is broken] [original link is broken] [original link is broken];. Hope it'll give you some ideas.

BR, Siarhei

Answers (1)

Answers (1)

Former Member
0 Kudos

You are on the right track. Is the number of possible plants limited? If yes, you could create all this at design-time and just use the needed context parts / table columns which would be much easier.

Armin

tom_cole3
Explorer
0 Kudos

The "Plants" as I described them are a combination of plants and sales orgs, so there is a definable limit (the total number of plants + the total number of sales orgs defined in the system) but this might be a bit cumbersome to manage

So far I have been able to build my node structure dynamically. I have also been able to dynamically enhance the table with the needed colums/headers/editors etc. This is all done in the wdDoModify method. The place where I am currently stuck now is populating these dynamically created nodes with elements...

Let's say that I have the id of one of the dynamically created nodes, I can use this to get the node info like so:

IWDNodeInfo node = approval.node().getNodeInfo().getChild(id);

I have a supply node (named Approvers) that I want to use to populate this dynamic node. So far I have this:

for (int j = 0, jlen = element.nodeApprovers().size(); j < jlen; j++) {
     //here I need to create an element in the dynamic node referenced by variable 'node'
     //I need to set this element's "Name" attribute to the "Name" atribute of element.nodeApprovers().getApproversElementAt(j);
}

I thought it would be great to use WDCopyService.copyElements(), but I don't know how to get an IWDNode reference to my dynamically create node, I only know how to get an IWDNodeInfo reference... Any hints

So close...yet so far away...

tom_cole3
Explorer
0 Kudos

I'm hoping to more clearly state my problem. I have to post in two messages because when I do it in one post something gets screwed up with the code tags, making it unreadable:

Part 1:

Maybe to more clearly state my problem:

My Context has two nodes, one that has the source data, and the other used to build my dynamic table structure mentioned earlier in the thread:

Context
     |
     ---- ApproverList (source node)
                |
                ---- Plant
                |
                ---- SalesOrg
                |
                ---- Department
                |
                ---- Approvers (non-singleton)
                            |
                            ---- Name

     |
     ---- Approvals (destination node)
                |
                ---- Department

For each unique "Plant" and/or "SalesOrg" in the ApproverList node, I am creating a dynamic non-singleton node in the Approvals node. Each of these nodes has a single attribute "Name". So given a simple structure like this in the ApproverList node:

Plant          Sales Org          Department          Approvers
Plant1                            Department 1        Approver 1
                                                      Approver 2
Plant2                            Department 1        Approver 3
                                                      Approver 4

I would create two dynamic non-singleton nodes under the Approvals node, named "Plant1" and "Plant2" respectively. Each of these two nodes would have a single Attribute, "Name".

The resulting structure would look like this:

Context
     |
     ---- Approvals 
                |
                ---- Department
                |
                ---- Plant1 (non-singleton)
                |         |
                |         ---- Name
                |
                ---- Plant2 (non-singleton)
                          |
                          ---- Name

tom_cole3
Explorer
0 Kudos

Part 2:

Next I would create a single Approvals element, setting the Department to "Department 1". I then need to locate the dynamic node for this element with the name "Plant1" and place in it two elements, one with attribute "Name" set to "Approver 1" and the other with attribute "Name" set to "Approver 2". Next would be to locate the dynamic node with the name "Plant2" in this same element and place in it two elements, one with the attribute "Name" set to "Approver 3" and the other with the attribute "Name" set to "Approver 4".

So far I have correctly been able to build the "Approvals" node with the desired dynamic nodes, each with the "Name" attribute. I have also successfully created the dynamic columns and editors in the table and mapped the "Texts" for the dropdown editor to the "Name" attribute of these dynamic nodes.

My problem is now getting the data from the ApproverList node into the needed form in the Approvals node.

My current approach (dummied down a bit for simplicity's sake):

for (int i = 0, len = wdContext.nodeApproverList().size(); i < len; i++) {
	String department = wdContext.nodeApproverList().getApproverListElementAt(i).getDepartment();
	String plant = wdContext.nodeApproverList().getApproverListElementAt(i).getPlant();
	for (int j = 0, jlen = wdContext.nodeApprovals().size(); j < jlen; j++) {
		if (wdContext.nodeApprovals().getApprovalsElementAt(j).getDepartment().equals(department)) {
			/*
			I need to get a handle on the non-singleton node for this approvals element that has an id equal to the plant variable.
			*/
			break;
		}
	}
}