cancel
Showing results for 
Search instead for 
Did you mean: 

Invalidate concept for value node and model node

Former Member
0 Kudos

Hello everybody,

We have invalidate method for value node and model node.

I want to know basic concept behind this method.

What this method acually does?

Regards,

Bhavik

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello,

My understanding of what happens is that the invalidate()-method tells the node that its referens to the underlying model is invalid, which causes the next call to the node to get a new reference to the model.

When we create a Input-node of RFC-modelNode we get ( -> meaning reference)


BAPI_XXX_INPUT              1->    modelBAPI_XXX_INPUT
   BAPI_XXX_OUTPUT          2->       modelBAPI_XXX_OUTPUT

when the execute() metod of modelBAPI_XXX_INPUT is called a new modelBAPI_XXX_OUTPUT containing the response is instanciated while or old reference (2->) still points to the old empty output.

Calling BAPI_XXX_OUTPUT.invalidate() simply tells the node that its referense is invalid and that it needs to get a new refernense pointing to the newly instanciated output-node.

Regards,

Mattias

Former Member
0 Kudos

Hi Bhavik,

Nice to see a question from your side :). But when you ask a question just like 'What does the invalidate() method acually do?', we all know it is something more than that. we have seen lot of replies from you asking to clear the node using invalidate() :). So even I'm very curious to know what you are upto???

I'll give you my understanding of the invalidate() method (beware, this is my understanding :). Though, nothing of these might be new to you and please correct me if I'm wrong.

invalidate() method simply clears the data from the node. If a view node is mapped to a component node, invalidating either of the node will clear data from both the nodes. Incase of model nodes, when you invalidate the node, the data is cleared from the view node and the component node. As far as i understand when we map a model node from the view to the model through the component, there is a close binding between the view node and the component node but not between the component node and the model node. So if we invalidate() the view node it will clear the data from the view node & the component node, but not from the model's node. And when we try to retrieve some data from the component node and if it is empty, it will again fetch the data from the model and populate the component node.

Best regards,

Nibu.

Former Member
0 Kudos

Hi Nibu,

Yes you are right. I give help and replies based on my experience, where we need to invalidate the node.I didn't get any problem with this. I am curious to know the basic concept behind this.

For value node:

When we invalidate value node it will remove all elements from value node.

For Model node:

We need to write invalidate after executing model to get response data in controller context. But, if we execute same model once again? It should refresh previous output and gives new response, Right?

This thing also works for me.

But, one more scenario:

I have model, one custom controller, component controller and view controller.

Model (Model node)

|_ Custom controller (Model node)

|_ Component controller (Model node), (value node)

|_ view (value node)

I have mapped RFC context from model to custom controller and costom controller to component controller. In component controller i am transfering model node data to some value node. Then this value node is mapped to view and displaying data.

I am executing RFC in custom controller. When i execute model second time it gives result appended with previous result.

One surprising thing in this is, if i get one record in each execution, then in second time of execution it gives two records but values in both records are same instead of the previous data. Means, data in element refreshed but element still exists there. And this element is filled with new data and also new data is appended.

I know it is very confusing. If you didnt understand then let me know.

If i invalidate node in component controller before executing RFC then what happens?

I have checked invalidating nodes in component controller. But, it didnt refresh data. I still able to print size of that node.

I am waiting for your inputs.

Thanks,

Bhavik

Former Member
0 Kudos

How do you copy the data from the modelnode to the valuenode in the component controller, I fail to see how you should get the data twice?

The modelnode should just be a referense to the data contained in the model, so invalidating a model node does not "refresh" data, it just makes sure the modelnode gets a fresh referense to the modelobject next time it is queried, at least that's my understanding.

Regards Mattias

Former Member
0 Kudos

I shall explain what my understanding in this regard is.

A model node unlike a value node do not contain the value in it. It is just reference to the value.

So when you invalidate a value node the value stored in it are flushed off whereas invalidating a model node enables the node to point it to the correct value.

http://help.sap.com/saphelp_nw04/helpdata/en/66/8b3c413b456e24e10000000a155106/frameset.htm

May be this link is better.

Former Member
0 Kudos

Hi Mattias,

I give you exact details.

When i executed first time with search id "123", it gives one record with values:

123 Bhavik SAP XXX

Then i executed again same model with value "234", it gives me two records with values:

234 XYZ ZXC XXX

234 XYZ ZXC XXX

If i execute once again with some other values lets say "567" it gives,

567 ZZZ YYY XXX

567 ZZZ YYY XXX

567 ZZZ YYY XXX

So, each time record increased.. I don't know why.

Hi Noufal,

I have looked at the document. My understanding was also same for invalidate. But, when i got problem in my project i got confused.

What could be the reason behind this?

Regards,

Bhavik

Former Member
0 Kudos

Hello,

Is that from the model or the value nodes? It seems strange if the model adds a record each time.

Regards ,

Mattias

Former Member
0 Kudos

Hi Mattias,

It is coming from model node.

I have displayed two tables one is bound to value node and second is bound to model node mapped with component controller.

Both giving me same value.

I resolved this problem by invalidating whole model and created model object once again and executing model.

But i know this is not the good practice. thats why i have posted this topic. So, i can optimize my code as well as can clear my concept for invalidate.

Regards,

Bhavik

Former Member
0 Kudos

Hi,

That's strange, I'm out of ideas, I'll have to test myself once I get back to our office (I'm also curious).

Regards,

Mattias

Former Member
0 Kudos

Hi All,

I am very new in webDypro but I think if you do the Invalidate of your Input like this before binding the problem will resolve:

wdContext.nodeZ_Web_Contract_Input().invalidate();

wdContext.nodeZ_Web_Contract_Input().bind(Contract_ele);

Sorry if I misinterpreted the problem.

Regards,

Prakash

Former Member
0 Kudos

Hi Mattias,

Yes thats why i have posted this query. I also curious to know why it is happening.

Hi Prakash,

Yes, i resloved problem using this method only. But, it is not a proper way of doing. Every time you are flushing old model object and creating new model object. We should achieve same thing through invalidate method only.

Regards,

Bhavik

I am sorry for not rewarding points. Because i can's see that radio button options. I don't know it is problem at my side or from SDN site. But, when i able to see it i will reward points.

Former Member
0 Kudos

Hello friends,

Sorry for late reply. I was out of town.

Any alternative instead of what prakash suggested?

Thanks,

Bhavik

Former Member
0 Kudos

Hi Bhavik

My two cents:

The concept of invalidation is more to with maintaing the integrity of the context than to do with nullifying the contents of a node.

Two main concept that helps to grasp the invalidation concept is <b>supplyFunctions</b> in case of value nodes and <b>supplyingRelation</b> role in the case of modelNodes.

Singleton nodes can have only one instance of itself (not to be confused with cardinality) , therefore when a parent node of singleton node has a change in the dataselected through lead selection , the child node should reflect this change by holding the data relevant to the parent node - because there can be only one instance, this instance should be rebuilt with the right child data and so a proper parent-child replationship is maintained in the context of data.To achieve this supplyfunctions are implemented that are invoked on <b>node invalidation</b> of the singleton node. The implementation is open to the developer on how this single instance should be rebuilt.

The model node also follows the same principle , If you observe the modelnodes are actually singleton nodes and have <b>supplyRelationRole</b> definition this defines how the model object to which the model node is bound is related to the parent model object. Model node <b>invalidation</b> is actually the execution of relationship, thereby refreshing the child nodes and the integrity of parent-child data relationships is maintained.

In simple terms when a node is being invalidate the supplyfunction or the supplyRelationRole is executed to populate the node with the right contents , if a supplyfunction or supplyRelationRole is absent which means the mechanism to refresh does not exist the node is nullified.

Regarding the second problem of the results being appended this an oft seen problem ,I worked around it by removing the elements from the node before execution.


List list = wdContext.currentNodeSome().modeObject().getSomes();
while(list.size() > 0){
 list.remove(0);
}

Regards

Pran

Former Member
0 Kudos

Hi Pran and all,

I figured out the problem. Input parameters are going multple times. So, depending upon that it gives multiple values.

My scenario is:

Root Node

|_ Input_node1

|_Attr1

|_ Input_Node2

|_Attr2

|_Output_node

|_Result

I am passing values in Attr1 and Attr2 attributes.

For this, first of all, i wrote following code.

In controller, i have initialized Root node:

Root_Node model = new Root_Node();

wdcontext.nodeRoot_Node().bind(model);

In view, I set values for attr1 and attr2 using following code:

Ipublic<View>.IInput_node1Element ele = wdcontext.createInput_node1Element();

ele.setAttr1("<value>");

wdcontext.nodeInput_node1().addElement(ele);

Ipublic<View>.IInput_node2Element ele1 = wdcontext.createInput_node2Element();

ele1.setAttr2("<value>");

wdcontext.nodeInput_node2().addElement(ele);

But this code didnt work. Model was executed without data in this case.

So, i thought that these elements were created at view level only. And corresponding model objects were not created.

*******************************************************

So, I have changed code like following way:

I have removed initialization code for Input_Node1 and Input_Node2 from view. Now, I am getting input values in two different value nodes. And before calling custom controller's method to execute model, I am making two ArrayLists and filling data in it. Now, i am passing these ArrayList objects as parameters to controller's method.

In this method, i am setting both values as follows:

wdcontext.currentRoot_NodeElement().modelObject().setInput_Node1(List1);

wdcontext.currentRoot_NodeElement().modelObject().setInput_Node2(List2);

Then i am executing my model.

But, When i am setting values for Input_Node1 and Input_Node2 as shown above, values are appended instead of overwritting the value. Because of this appended values, it gives mupltiple results.

****************************************************

Means, Both ways are not proper. What should be the proper and best way to pass values in this case?

Thanks,

Bhavik

Former Member
0 Kudos

Hi Bhavik

Looks okay to me , try inspecting the contents of your modelobject after population , this will validate if your contents are actually getting populated

wdContext.currentRootElement().modelObject().toXml()

If the Arraylists are being populated within the execute method then there can be no possibility of list being appended , you must be initialising ArryaList as a class member within the controller (thus initalising only once within the lifecycle of the controller, thereby holding previous values).

Regards

Pran

Former Member
0 Kudos

Hi Pran,

I have looked into modelobject from debugging. It is showing me multiple values there under input node.

And can you please elaborate <b>"If the Arraylists are being populated within the execute method then there can be no possibility of list being appended , you must be initialising ArryaList as a class member within the controller (thus initalising only once within the lifecycle of the controller, thereby holding previous values).

"</b>

The way i am populating the data is ok or not??

Which way is better to do this?

Thanks,

Bhavik

Former Member
0 Kudos

Hi Bhavik

The second method seems okay to me,


wdcontext.currentRoot_NodeElement().modelObject().setInput_Node1(List1); 
wdcontext.currentRoot_NodeElement().modelObject().setInput_Node2(List2);

Question:

List1 and List2 where is declared and initialized?

Regards

Pran

Former Member
0 Kudos

Hi Pran,

I am populating these two lists in my view. And then i am calling one controller's method and passing these two lists as parameters in this method.

In controller's method, then i am binding these to Lists with model. And then i am executing my model.

Regards,

Bhavik

Former Member
0 Kudos

Yup,

But the two lists are they declared inside a method or way bottom where declarations can be made.

Are the lists empty in the second time the code is run or do they appear populated?

Within the function module are the tables used for entry refreshed after execution?

Regards

Pran

Former Member
0 Kudos

Hi Pran,

I have declared it in view. And then i am passing it to controller's method. Inside this method i am binding lists and then executing Model.

In debug mode, i have checked that values are coming properly in this list each time. And it appends these values each time to model object.

I didn't understand <b>"Within the function module are the tables used for entry refreshed after execution?"</b>

I am not using Function module. I have made model of the web service.

Regards,

Bhavik