cancel
Showing results for 
Search instead for 
Did you mean: 

Invalidate

Former Member
0 Kudos

Hi,

can someone explain me the difference between using .invalidate() and using a loop to remove all the node elements from a node? (distinguishing the case of a value node and of a model node).

node.invalidate();

vs.

while (node.size() > 0)
   node.removeElementAt(0);

Thank you,

Pietro

Accepted Solutions (1)

Accepted Solutions (1)

Stefan-EA
Contributor
0 Kudos

>

> Hi,

> can someone explain me the difference between using .invalidate() and using a loop to remove all the node elements from a node? (distinguishing the case of a value node and of a model node).

>

>

node.invalidate();

> vs.

>

while (node.size() > 0)
>    node.removeElementAt(0);

>

> Thank you,

> Pietro

Invalidate will remove all node elements from a value node.

On a model node, invalidate will synchronize the context with the model. This is why you always invalidate the model node

after calling an RFC.

To remove elements from a model node, you have to loop through it and remove an element at each iteration.

Former Member
0 Kudos

Thank you Stefan,

at least now i know exactly how it works (and that useful explanation is not reported in the javadocs).

Thank you again,

Pietro

Former Member
0 Kudos

Hi Stefan,

But even i tried to remove it one by one.

That doesnt work too .

I have the code below

for(int i=0;i<wdContext.nodePersons().size();i++)

{

wdContext.nodePersons().removeElement(wdContext.nodePersons().getPersonsElementAt(i));

}

Former Member
0 Kudos

You can't use a for loop and then reevaluate the ending condition using .size() each time.

You have to use a while loop like I wrote in the first post.

If you use your For loop, this is what happens:

i = 0; is 0 < size? Yes, remove element 0 --> You have now (size -1) elements

i = 1; is 1 < (size - 1)? Yes, remove element 1 --> You have now (size -2) elements

...

i = size /2; is size/2 < size/2? No, end the cycle.

Answers (3)

Answers (3)

Former Member
0 Kudos

.

Former Member
0 Kudos

Thank you for your reply.

Still, I can't figure out why sometimes the model node get cleared and sometimes not. What is the reason of this behaviour?

Pietro

Former Member
0 Kudos

Hi,

if u use inavlide it will delete the all values of context atrributes in that node .(cordinality 1:1 here )

where as if u use loop u are getting a chance to delete particulr element attribute value (cordnality is 0-n or 1-n) .

Regards,

Govindu

Former Member
0 Kudos

Hi Govindu,

thank you for your reply but I don't understand what you said.

Do you mean that invalidate and looping through the NodeElement collection is the same? For both value and model nodes?

Thank you,

Pietro

0 Kudos

Hi Pietro,

Yes it is same but if you use invalidate method for Model node some times it won't delete the data in model node, so for model nodes best practice is to use the remove element method while using the model node.

hope this will help you.

Thanks & Regards,

Bhargava.