cancel
Showing results for 
Search instead for 
Did you mean: 

doubt on invalidate() and when_visible proerty of view

p_k3
Participant
0 Kudos

Hi All,

i have a doubt on invalidate method of the cntext and the when_visible property of the views

I am writing a simple application where in i have 2 windown each containing one view.

window1 has view1 which has a button.... upon clicking the button i display the window2 as a dialog box which has view2 contianing a simple table with 2 columns bound the view2's context attributes... i am populating the view2's context in the doinit() of the view2..... thus i am creating 10 rows for the table ifn the view2.

now i want only these 10 rows every tiem i display the button.... so at the beginning of the doinit of view2 i am calling invalidate() on the value node so that the previous contents n the same rows would be added as fresh content.... when i remove the invalidate 10 new rows are being added so calling invalidate() was a must for me...

now just for testing i removed the invalidate() and set the life_span of view2 to "when_visible" thinking that it would destroy the context also when ever the view2 is removed from display thus removing and clearing its context... but it is not happenign so... when ever i display the view2 the previous contents are still there and 10 new rows are being added to its context

now my question is that doesnt the when_visible property of a view instruct the WD framework to destroy its context and its contents also? read in help sites that this property controls the life span of a view's controller... when it controls the view's controller life span then it should also control the view's contenxt life apsn also (please correct me if i am wrong)

ca some one explain me when my understanding of the relation between a view's context and its when_visible propertty is going wrong?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Friend,

In Addition you can check the collection cardinality of the node which you want to invalidate. If the cardinality is 1-1 or 1-n then the previous values will be flushed and the new values will be populated to the node again in you case the values will be refreshed by the new values, if the cardinality is 0-1 or 0-n then the values will be cleared the new values will not come.

Hope it will help.

Regards

Jeetendra

p_k3
Participant
0 Kudos

Hi Satyajit, Tushar and Jitendra,

Thanks for yorr replies.

My doubt is cleared now. I was under the understanding that even the mappend nodes elements to would be cleared when the property is set to "when_visible".

Rewareded points to all of you

--

PK

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi PK,

You were correct in the understanding of "wdcontext.node<YourNode>().invalidate()" method which invalidates the (view's/component's) controller context every time you call it in your implementation and is executed. And, it will also invalidate the nodes it is mapped to in other controllers (may be component controller/custom controller/interface controller/other views through any of these controllers).

But, setting the property of the view to "when_visible" will only destroy the created instance of the view and the unmapped context within. So, every time you call this view, the wdDoInit() of the view would be called and 10 elements created under its context node as you have put in the code in the wdDoInit(), but the mapped nodes and its attributes are retained in the component controller though context mapping even after you destroyed the view. So, now when the instance of the view is created, then it will populate 10 elements from the component controller and then create you explicitly defined 10 elements in wdDoInit() of the pop-up view and hence the no. of elements in the table will keep on increasing.

Therefore, in your case,

better be careful in the usage of these two properties. But you can use either of them. I will tell you how.

1. Use the invalidate() method to clear of the earlier values in the context (even if mapped doesn't matter) on close of the Pop-up and recreate the elements in wdDoInit() of the pop-up view.

2. If you want only 10 fixed elements to be there in the context of the pop-up view all the time, then create these 10 elements in the wdDoInit() of the component controller (which will be created only once) and map it to the context of the pop-up view (which will retain the node elements even though you have destroyed the component controller).

Hope your issue is well addressed.

Regards,

Tushar Sinha

Former Member
0 Kudos

Hi,

You are right - when a view's lifespan is set to "when visible" & when the view becomes invisible (via user navigation, for example) then "wdDoExit()" is called. The view controller and its attributes and the local view context are deleted. Also the UI element tree for that view is deleted as well.

But if you hold references to the view context externally by mapping to other controller contexts then these references will not be released. So the question for you is have you mapped the second view's context to the component controller context or any other controller contexts?

Regards,

Satyajit