on 06-04-2007 2:40 AM
I'm trying to get my head around on how to dynamically create childnodes and attributes. I'm trying to create this structure.
Target Structure
<root node>
+ Parents (c=1..1, s=true)
-- mother
-- father
-- + Children (c=0..n, s=false)
----- name
----- age
I've written the sample code below.
I get a com.sap.tc.webdynpro.progmodel.context.ContextException: NodeElement(.TestView.Parents): unknown attribute name
when I try and execute child1.setAttributeValue("name", "Madison");
I suspect my problem is here
IWDNode childElement = wdContext.getChildNode("Parents.Children",IWDNode.LEAD_SELECTION);
because it returns null.
What am I doing wrong
Thanks for your help.
/Greg
// Dynamically create a context node
IWDNodeInfo parents = wdContext.getNodeInfo().addChild(
"Parents", // Name of node
null, // elementClass
true, // singleton
true, // mandatory
false, // multiple
true, // mandatorySelection
false, // multipleSelection
true, // initializeLeadSelection
null,
null,
null);
parents.addAttribute("mother", "ddic:com.sap.dictionary.string");
parents.addAttribute("father", "ddic:com.sap.dictionary.string");
IWDNodeInfo children = wdContext.getChildNode("Parents",0).getNodeInfo().addChild(
"Children", // Name of node
null, // elementClass
false, // singleton
true, // mandatory
true, // multiple
true, // mandatorySelection
false, // multipleSelection
true, // initializeLeadSelection
null,
null,
null);
children.addAttribute("name", "ddic:com.sap.dictionary.string");
children.addAttribute("age", "ddic:com.sap.dictionary.string");
IWDNode parentElement = wdContext.getChildNode("Parents",0);
IWDNodeElement p = parentElement.createElement();
p.setAttributeValue("mother", "Amy");
p.setAttributeValue("father", "Greg");
IWDNode childElement = wdContext.getChildNode("Parents.Children",IWDNode.LEAD_SELECTION);
IWDNodeElement child1 = parentElement.createElement();
child1.setAttributeValue("name", "Madison");
child1.setAttributeValue("age", "2");
IWDNodeElement child2 = parentElement.createElement();
child2.setAttributeValue("name", "Peyton");
child2.setAttributeValue("age", "1");
Message was edited by:
Greg Preston
Hi Greg,
it must be
IWDNode parentNode = wdContext.getChildNode("Parents",0);
IWDNodeElement p = parentNode.createElement();
p.setAttributeValue("mother", "Amy");
p.setAttributeValue("father", "Greg");
parentNode.addElement(p);
IWDNode childNode = parentNode.getChildNode("Children", IWDNode.LEAD_SELECTION);
IWDNodeElement child1 = childNode.createElement();
child1.setAttributeValue("name", "Madison");
child1.setAttributeValue("age", "2");
childNode.addElement(child1);
IWDNodeElement child2 = childNode.createElement();
child2.setAttributeValue("name", "Peyton");
child2.setAttributeValue("age", "1");
childNode.addElement(child2);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
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.