on 06-06-2005 1:52 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Question: Why do you create context nodes at runtime and not at design time?
Node names must be unique across a context.
Armin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.