cancel
Showing results for 
Search instead for 
Did you mean: 

Difference in node behaviour in action handler and supply function

Former Member
0 Kudos

Hi,

I have got a view called TableView and I have defined a value node called TableData in its context.

I have a button called "Create" which has an event handler called Create.

In onActionCreate , I am trying to create a new element in the node TableData.

For this I have :


Approach 1:
// This doesn't work as createAndAddElement() is undefined on ITableDataNode
ITableDataElement element = ITableDataNode.createAndAddElement();
/*Fill up the element */

Approach 2:
//This works
ITableDataElement element = (ITableDataElement)wdContext.nodeTableData().createAndAddElement();
/*Fill up the element*/

However, when I define a supply function for TableData Node and try to fill it using Approach1 it works.

The code looks like


 for (int i=0; i<5 ; i++){
      /* node is IPrivateTableView.ITableDataNode passed to the supply function by the framework */
	 ITableDataElement element = (ITableDataElement) node.createAndAddElement();
	 element.setName("HarryPotter"+i);
	 element.setPrice(100*i);
	  }

Can you please guide me as to why Approach 1 doesn't work in onActionCreate()

Regards,

Arvind

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

If your context node is named "TableData" then you should use


wdContext.nodeTableData().createAndAddTableDataElement()

in the action handler, and


node.createAndAddTableDataElement()

in the supply function of node "TableData".

Armin

Former Member
0 Kudos

Also, to add to what is mentioned in the post above, TableData node is passed to the supply function method as an argument and can be directly referenced inside the method as 'node'.

A supply funtion is always defined for one particular node & this method shall thus understand which node's elements need to be created...(to which node is it supplying the data).

former_member201361
Active Contributor
0 Kudos

Hi Arvindj,

In onActionCreate , I am trying to create a new element in the node TableData.

For this I have :

Approach 1:

// This doesn't work as createAndAddElement() is undefined on ITableDataNode

ITableDataElement element = ITableDataNode.createAndAddElement();

/*Fill up the element */

Approach 2:

//This works

ITableDataElement element = (ITableDataElement)wdContext.nodeTableData().createAndAddElement();

/Fill up the element/

There is no difference in Node behaviour in action handler and Supply function.

In Approach1 -->

U are creating a element of type IWDNodeElement and assiging it to ITableDataElement .

thats why , u are getting erro in design time.

In Approach2 -->

This is the right approach to create node element

U are creating a element of type ITableDataElement and assiging it to ITableDataElement ref.

The code looks like

for (int i=0; i<5 ; i++){

/* node is IPrivateTableView.ITableDataNode passed to the supply function by the framework */

ITableDataElement element = (ITableDataElement) node.createAndAddElement();

element.setName("HarryPotter"+i);

element.setPrice(100*i);

}

Please note that , when u create a Supply function , the method signature for ur suuply function is ,

voidSupplyTableData(IWDNode TableData, IWDNodeElement parentElement){

}

Here the parameter node points to TableData node .

so in this case there is no problem in using createAndAddElement method.

here node represents as wdContext.nodeTableData().

ITableDataElement element = (ITableDataElement) node.createAndAddElement();

element.setName("HarryPotter"+i);

Hope it helps

Thanks and Regards

Former Member
0 Kudos

Hi Fazal , Pravesh,

Approach 1 fails in on Action Create even after typecasting. The error that I get is

Cannot make a static reference to the non-static method createAndAddElement() from the type Node

But it works fine in supply function.

Is there any difference the way WD treats the node in supply function .

Thanks & Regards,

Arvindham Ashish

pravesh_verma
Active Contributor
0 Kudos

Hi Arvind,

Pelase refer to the reply whichI have given above. Please understand that there are 2 things:

1) create and add element of IWDNodeElement type.

2) create and add element of <NODE>Element type.

In bothe cases there is a difference. If you use 1st way of creating teh element then you need to type cast the node creation if you want the return type as a specific nodeElement type.

As you said your approach 1 wil not work even with typecasting that is correct. Use this code:


ITableDataElement element = (ITableDataElement) wdContext.nodeTableData().createAndAddElement();

OR


ITableDataElement element = wdContext.nodeTableData().createAndAddTableDataElement();

In case 2) when you are creating a <NODE>Element type, in that case WD expects the return type as that of specific <NODE>Element type.

I hope this clears you issue! Please revert back if you have still not understood.

Thanks and Regards,

Pravesh

Former Member
0 Kudos

Hi Pravesh,

Thanks for taking the pains.

Perhaps I have not been able to state the issue clearly.

The issue is that onActionCreate when I refer to node TableData using

IPrivateTableView.ITableDataNode , I don't get the method

createAndAddElement();

That is to say IPrivateTableView.ITableDataNode.createAndAddElement()

doesn't exist in onActionCreate.

In this, IDE shows me the error

"Cannot make a static reference to the non-static method createAndAddElement() from the type Node"

In the supply function, the same node is pass as a parameter to the method

and over there I get the createAndAddElement() method on this node.

That is to say

node.createAndAddElement() exists where node is IPrivateTableView.ITableDataNode.

I wanted to know is that how come I am able to make reference to non-static method createAndAddElement() from the type Node in supply function but not in action handler.

Hope this clarifies the question.

pravesh_verma
Active Contributor
0 Kudos

Hi Arvind,

The approach 1 doesnt work because:

ITableDataElement element = ITableDataNode.createAndAddElement();

is not a valid statement for creating a node element for TableData node. In this case createAndAddElement returns a IWDNodeElement which is not the return type of the object "element". The return type is ITableDataElement.

You should use this statement:


    ITableDataElement element = ITableDataNode.createAndAddTableDataElement();

This will definitely work as the return type is same. In second approach it worked as you have type casted the IWDNodeWElement by ITableDataElement. And therefore the return typeis correct now. I am sure it would not have worked in that case as well if the type casting would not have been done.

I hope this clarifies the issue. If you have any further issues then please revert back.

Thanks and Regards

Pravesh

Edited by: Pravesh Verma on Mar 6, 2009 5:40 AM

Former Member
0 Kudos

Hi Pravesh,

Thanks for your inputs. Typecasting is not the issue. I missed out to add typecasting in approach 1.

Even if I add typecasting , it doesn't work


ITableDataElement element = (ITableDataElement)ITableDataNode.createAndAddTableDataElement();
//This doesn't work as ITableDataNode doesn't have a createAndAdd method defined.

Hoewever this approach (apporach 1) ,works fine for supply method.

I would like to know as to how the node TableData is treated differently in the supply method.

Regards,

Ashish

pravesh_verma
Active Contributor
0 Kudos

Hi Ahish,

Sorry for my mistyping. I have missed it!! I have to write:


    ITableDataElement element = wdContext.nodeTableData().createAndAddTableDataElement();

Try this this will deifinitely work. Reason is same what I have mentioned earlier.

However please note that typecasting does matter!!

Try this in your 2nd approach:


ITableDataElement element = wdContext.nodeTableData().createAndAddElement();

this will never work and it will give compile time error. The only reason why it was working was the typecasting which you have done.

In the supply function you have used :


ITableDataElement element = (ITableDataElement) node.createAndAddElement();

PLEASE NOTE THAT : Here the node itself is the IWDNode instance and therefore you have used the createAndAddElement() along with the typecasting.

If you would have used this line of code:


IWDNodeElement element = node.createAndAddElement();

Then that would have also worked but the clear difference is of return type. Here it has returned the IWDNodeElement instance and in otehr case it has returned you ITableDataElement.

I hope that clarifies your issue. Please revert back if you any issue, else close the thread.

Thanks and Regards

Pravesh