cancel
Showing results for 
Search instead for 
Did you mean: 

Error creating and setting attributes on Childnode

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

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);

Former Member
0 Kudos

Maksim,

Yours did make more sense than what I put together and it worked. Thanks for your response.

/Greg

full points awarded.

Answers (0)