cancel
Showing results for 
Search instead for 
Did you mean: 

Writing Data into Context

Former Member
0 Kudos

Hi,

I have 5 elements which I need to read from a URL. I get these 5 elements in the Interface Controller and pass them to a function (Initialise) in the Controller.

In the Controller Context I have created a node (ABC) and have 5 Value attributes to this node.

In my Controller function(Initialise), I am trying to set the values in the node as follows:

wdContext.currentABCElement().setElem1( "123");

wdContext.currentABCElement().setElem2( "abc");

wdContext.currentABCElement().setElem3( "xyz");

wdContext.currentABCElement().setElem4( "hij");

wdContext.currentABCElement().setElem5( "klm");

In my wdInit() of the controller I am trying to retrieve the values in the node using the following:

wdContext.nodeABC().currentABCElemen().getElem1();

It throws me a null Pointer Exception, any thougths as to what may be the problem. Any help would be appreciated.

~NAC

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos
Former Member
0 Kudos

What's the cardinality of the node? If it's 0..n (meaning you're going to store a collection), then there is no backing storage in the context to store your data. In this case, you need to allocate and populate the node:

IABCElement elt = wdContext.createABCElement();

elt.setElem1( "abc" );

...

You might want to consider using a supply function, which is defined at the node level in your context. The runtime will automatically call your supply function to populate the context - you would fetch your URL information, create the node as above, and then just go

node.addElement( elt );

If you want to store a single item, change the cardinality to 1:1, and then just access the node - it should already be there.

Former Member
0 Kudos

Ken,

you mentioned "Supply Function", I am new to Webdynpro, is there anything I can read about the same.

Thank u

~NAC

Former Member
0 Kudos

Hi,

Whatever you are doing is fine.

But, problem is due to initialization of node.

I guess you have set cardinality of your node to "0..N". So, there are two options:

change cardinality to "1..N" or write initialization code in the wdinit method of the controller.

Code is :

ipublic<controllername>.i<node name>element ele = wdcontext.create<node name>element();

wdcontext.node<node name>().bind(ele);

It will initialize your code.

Then you can set values and later on retrieve the values.

Regards,

Bhavik

Former Member
0 Kudos

A supply function is called by the Web Dynpro runtime to populate a context node. On your context node (the one that will contain your data - either in your model, or controller), right click and select 'Properties'. There should be an entry in the properties list for 'Supply Function' - use this entry to define a supply function.

You then manualy create and add elements to the passed in 'node' object.