cancel
Showing results for 
Search instead for 
Did you mean: 

Node Hierarchy and Error Behaviour

Former Member
0 Kudos

hi,

when in the root context I create a string value attribute which is being fed with any data, and this context attribute being assigned for example to a textview, then everything is fine, when coding

wdContext.currentContextElement.get....

When I try to organize my attributes in value nodes I get Null Pointer exceptions. Why is that?

According to an example I found, I tried this code (having created a context node Date with attributes strDate, strTime):


	IWDNodeInfo rootNodeInfo = wdContext.getNodeInfo();
	  
		 IWDNodeInfo DatumInfo = rootNodeInfo.addChild(
		   "Date", 
		   null, 
		   true, 
		   false, true, 
		   false, false, 
		   false, 
		   null, 
		   null, 
		   null);
// add Attribute metadata to new node info object		   
		   DatumInfo.addAttribute("strDate", "ddic:com.sap.dictionary.string");
		   DatumInfo.addAttribute("strTime", "ddic:com.sap.dictionary.string"); 	
// create new ContNode using the metadata we just created
		  IWDNode DatNode = wdContext.getChildNode("Date",0);
// create New Elements
			IWDNodeElement eDate = DatNode.createElement();
			IWDNodeElement eTime = DatNode.createElement();
			eDate.setAttributeValue("strDate", "Datum: "+strDatValue);
			eTime.setAttributeValue("strTime", "Uhrzeit: "+strUhrValue);
			
			DatNode.addElement(eDate);
			DatNode.addElement(eTime);

which in turn delivers this:

<i>Error stacktrace:

com.sap.tc.webdynpro.progmodel.context.ContextException: NodeInfo(Step5): duplicate name for child node Date

at com.sap.tc.webdynpro.progmodel.context.NodeInfo.addItem(NodeInfo.java:347)

</i>

Of course I created in the context a Node called "Date", and attributes strDate and strTime. strDatValue is filled beforehand with the actual date.

any hint appreciated,

regards, matthias

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

according to armin and krish, i suppose i misunderstood the example in the webdynpro book, i am reading - apparently the illustration of the context is merely an image to understand what the author is trying to create in the coding. so, ok, i have got double entries which lead to the exception.

I don't get this exception when deleting the Date node in the context tab (design time?).

But then I don't know how to bind the data to a textview created in the layout - maybe some more coding required for that aim?

regards, matthias

Former Member
0 Kudos

You want to bind the "text" property of a TextView element to a context attribute?

Open the view layout, select the TextView element in the outline. In the properties sheet, look for the "text" property, select "..." to open the context editor and select the attribute. Done.

Armin

Former Member
0 Kudos

Armin,

when I develop my context node in wdDoInit, like described in my very first post (during runtime as you say), then I don't get any visible nodes in the context tab. So I can't do the binding like you suggest. This is the strange problem. I have tested three strategies now:

1) create context in design time - creating value node and attributes like this:

| root
  |
  | Date
         - strDate
         - strTime

I bound the attributes to textview --> returns Null Pointer Exception, when deployed an run

2) did both - context in design time and during wdDoInit

--> returns duplicate Names Error when deployed and run

3) create context in wdDoInit - seems to work, but now i can't bind the context (see the code of my very first entry) to UI-Element textview.

The point is: I don't get any trouble when putting the context attributes "strDate" and "strTime" in the context root! Binding works perfectly then. For organizing purposes I want a value Node. And I assume that it works somehow. But sofar, I have no clue.

As I am not the JavaExpert I would like the design time solution to work. Maybe it is something to do with Patchlevels? I am on 10.

regards, Matthias

Former Member
0 Kudos

Perhaps you mix the concepts of nodes and node elements. If you create a value node, it has default cardinality 0:N. This means, it may contain (at runtime) zero or more node elements which are "records" with attributes as defined in the node.

These "records" carry the data, so you must create instances thereof (node elements). or you declare the cardinality to be 1:1 or 1:N, and you get at least one node element automatically.

For the root node, there is always a node element created automatically.

Armin

Former Member
0 Kudos

how do i set up the cardinality so that the node and attributes show up? the 4th boolean parameters determine the cardinality - I guess I need 1:n

IWDNodeInfo DatumInfo = rootNodeInfo.addChild(
		   "Date", 
		   null, 
		   true, 
		   <b>false, true,</b> 
		   false, false, 
		   false, 
		   null, 
		   null, 
		   null);

still i don't see a value node in my context root.

In my case, all this happens during wdDoInit.

regards,

matthias

Former Member
0 Kudos

Why do you create nodes at runtime? Use the context editor.

Armin

Former Member
0 Kudos

Hi Armin et al,

your post before was the decisive hint - I just did not care about the properties of the value node (in the context editor). Now I changed the cardinality from standard 0...n to 1...n! I dropped the whole context runtime-coding and did it all in the context editor.

The trouble was, that I didn't realize, the standard properties of context nodes (cardinality) lead towards Null Pointer Exception.

Thank you again, and all the other contributors ,

Matthias

Answers (2)

Answers (2)

Former Member
0 Kudos

I Think Asfar as The Error is concerned

There is already a Node Named Date which u r trying to create i suppose

So just check that

Former Member
0 Kudos

Question: Why do you create context nodes at runtime and not at design time?

Node names must be unique across a context.

Armin

Former Member
0 Kudos

Hi Armin,

design time means using the context tab (to create context variables), right?

I was following an example in the book "inside webdynpro for java", where they do it like that (page 109ff).

when I miss out the quoted coding above I get the Null Pointer Exception. So if I create a Node and attributes using the context tab and coding:


wdContext.currentDateElement().setStrDate(strDatValue);

I get the Null Pointer...

matthias

Former Member
0 Kudos

See

Check whether u have instantiated the Node before using it but this is Applicable only if ur node cardinallity is 0..n.

See to it that ur Date Node is Instantiated before u r using the same

And Check whether the in AddChild try to give different name other that Date

Former Member
0 Kudos

Hi Kasig,

I guess you have not instantiated your node. write following coding in your view's init method.

iprivate.idate ele = wdcontext.createdateElement();

wdcontext.nodeDate().bind(ele);

Add this code and then check once again.

Regards,

Bhavik