cancel
Showing results for 
Search instead for 
Did you mean: 

problem with filling nodes of a context with data

achim_hauck2
Active Contributor
0 Kudos

hi,

i've got the following problem with filling a controller context:

the context of the controller looks like:

Context

|-Node1 0..n singleton

|-Subnode1 0..n singleton

| |-SubVal1.1

| |-SubVal1.2

|-Subnode2 0..n singleton

| |-Subval2.1

| |-Subval2.2

|-Val1.1

|-Val1.2

that means every Element of Node1 should have its own Subnode-Elements & Val1-Values

in wdDoInit() of the controller I fill the context like this:

Collection Node1, SubNode1, SubNode2

for (Iterator iter = Node1.iterator(); iter.hasNext;) {

newNode1NodeElement = wdContext.createNode1Element();

newNode1NodeElement.set... //setting the values

wdContext.nodeNode1().addElement(newNode1NodeElement);

for (Iterator iter2=Subnode1.iterator(); iter2.hasNext;) {

newSubnode1NodeElement = wdContext.createSubnode1Element();

newSubNode1NodeElement.set... // setting the SubVal1.x

wdContext.nodeSubnode1.addElement(newSubnode1NodeElement);

}

for (Iterator iter3=SubNode2.iterator(); iter3.hasNext;) {

newSubnode2NodeElement = wdContext.createSubnode2Element();

newSubNode2NodeElement.set... // setting the SubVal2.x

wdContext.nodeSubnode2.addElement(newSubnode2NodeElement);

}

}

i've got the impression, that <b>all</b> my SubNodes are filled in the <b>first</b> Node1-Element. is there an error in the code above? because in the first place, i see every values in the first Element of Node1-views and if i navigate to the next Element of Node1, every views are empty.

for every Node (Node1, Subnode1, Subnode2) i've got an own view, that maps its context to the corresponding Node of the controller context, e.g for the SubNode1-View:

Context Context

| ....

|- ViewNode ---> ..|- Subnode1

|- SubVal1.1 ---> .. |-SubVal1.1

|- SubVal1.2 ---> .. |-SubVal1.2

....

in these views, i navigate through the nodes via

wdContext.nodeViewNode().move...()

in the SubNode1-View i see the SubVal1.1, SubVal1.2 (that's what i want) <b>and</b> additional SubVal2.1, SubVal2.2 (that's what I don't want...)

kind regards, achim

ps: i've studied the Master/Detail-Tutorial and i think the choice for cardinality 0..n and type singleton is correct in my case.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Achim,

The problem is that you define Subnode1 & Subnode2 as singletons. This means that these nodes keep elements only for lead selection path (i.e. currently selected parent <- currently selected grand parent <- ... )

So you have 2 options:

1. Make them non-singleton and keep your code as is.

2. Provide a supply functions for sub-nodes. These functions will be called on whenever data for subnodes is required for given parent element in Node1.

However, be aware that all singleton subnodes' elements for given parent are discarded when you select diferent element in Node1. So [2] might be usefull for read-only data or for model nodes.

Regards,

VS

achim_hauck2
Active Contributor
0 Kudos

Valery,

i've declared both subnodes as none-singelton now, but all values are still displayed for the first Node1 Element, the second Node1 Element has no entries.

But with the declaratoin of non-singleton, i've reached that when navigating back to the first Node1-element, the data is still there (with singleton, the data disappearded) as you pointed out.

is there probably a problem with using different views for displaying the context-data from one context and navigating in these views?

or is there still a bug in the wdDoInit() method when i fill the controller context? (sorry for the bad formating style in my code

kr, achim

Former Member
0 Kudos

I have to read questions more attentively

There is an error in logic (see emphasized lines)

Collection Node1, SubNode1, SubNode2

for (Iterator iter = Node1.iterator(); iter.hasNext;) 
{
  newNode1NodeElement = wdContext.createNode1Element();
  newNode1NodeElement.set... /* setting the values */
  wdContext.nodeNode1().addElement(newNode1NodeElement);
  for (Iterator iter2=Subnode1.iterator(); iter2.hasNext;) 
  {
    newSubnode1NodeElement = wdContext.createSubnode1Element();
    newSubNode1NodeElement.set... /* setting the SubVal1.x */
    <b>wdContext.nodeSubnode1</b>.addElement(newSubnode1NodeElement);
    <b>Must be:
    newNode1NodeElement.nodeSubnode1().addElement... 
    </b>
  }
/*
  Same for Subnode2
*/
...

wdContext.nodeSubnode1 refer to subnode of element at lead selection (always first element in your case).

VS

achim_hauck2
Active Contributor
0 Kudos

that's it, thank you very much!

kr, achim

achim_hauck2
Active Contributor
0 Kudos

me again,

i thought i understood this point, but if i put a node <b>one hierarchy deeper</b>, let's say SubNode1.1 under SubNode1, shouldn't the the setting be:

newNode1NodeElement.nodeSubnode1().nodeSubnode1.1.addElement... ?

i also tried newSubnode1NodeElement.nodeSubnode1.1.addElement...

but both variants produce false results.

kr, achim

Former Member
0 Kudos

The process is recursive.

You need first save reference to newly created element of Subnode1, say el, and then call el.nodeSubnode1_1().addElement()

VS

achim_hauck2
Active Contributor
0 Kudos

hmm, let's look at the code:


for (Iteration Node1) {
  newNode1NodeElement = wdContext.createNode1Element();
  ...
  wdContext.nodeNode1().addElement(newNode1NodeElement);
  for (Iteration SubNode1) {
     newSubNode1NodeElement = wdContext.createSubNodeXElement();
     ...
     newNode1NodeElement.nodeSubNode1().addElement(newSubNode1NodeElement);
     for (Iteration SubNode1.1) {
        newSubNode1.1NodeElement = <b>wdContext</b>.createSubNode1.1Element();
        ...
        newSubNode1NodeElement.nodeSubNode1.1.addElement(newSubNode1.1NodeElement);
     }
   for (Iteration SubNode2) {
      newSubNode2NodeElement = wdContext.createSubNode2Element();
      ...
      newNode1NodeElement.nodeSubNode2.addElement(newSubNode2NodeElement);
   }
}

is there an error in creating the SubNode1.1-Node (bold line)?

if the code is correct, perhaps it's only a viewing problem:

i use views that point on every node and display the values in that node. if i move in the view for Node1 to another node, the values for SubNode1 point to the correct values too, but the values for SubNode1.1 still stay on the old values. is the move of a grandfather node not correctly propagated to his first child?

kr, achim

Answers (0)