Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

Recently by a query in SDN, was I introduced to this particular scenario of accessing a node dynamically in WebDynpro. The problem was that of getting a null pointer exception while execution. The topic might seem pretty simple; after all it is just a child’s game to create a node dynamically. So what is the big deal in accessing the dynamically created node. This was the impression the post gave me initially.

The scenario is as follows

Context
|
NodeA(Statically created)
|______NodeAB(Dynamic singleton)
           |________NodeABC(Dynamic NonSingleton)
                      |________NodeABCD(Dynamic NonSingleton)
                      |________AttbA
                      |________AttbB

The problem was however that there was no element being created; and that it was not able to access the NodeABC with the following code.

IWDNode node = wdContext.nodeNodeA.getChildNode(“NodeAB”,IWDNode.LEAD_SELECTION).getChildNode(“NodeABC”,0);

This code returned a null value and the node.createElement() caused the exception.

So I felt that this piece of code might be useful for someone who might be having a tough time with creation and accessing nodes with dynamic programming.



IPrivateDynAppView.INodeAElement ele=wdContext.createNodeAElement(); wdContext.nodeNodeA().addElement(ele);
IWDNodeInfo salesOrgs = wdContext.nodeNodeA().getNodeInfo();
IWDNodeInfo salesOrg = salesOrgs.addChild("NodeAB",null,true,true,true,false,false,true,null,null,null);
IWDNodeInfo salesOrgElement = salesOrg.addChild("NodeABC",null,false,true,true,false,false,true,null,null,null);
salesOrgElement.addAttribute("AttbA","ddic:com.sap.dictionary.string");
salesOrgElement.addAttribute("AttbB","ddic:com.sap.dictionary.string");
salesOrgElement.addChild("NodeABCD",null,false,true,true,false,false,true,null,null,null);

IWDNode node=wdContext.nodeNodeA().getChildNode("NodeAB",IWDNode.LEAD_SELECTION);
IWDNodeElement elem=node.createElement();
node.addElement(elem);
IWDNode divNode=wdContext.nodeNodeA().getChildNode("NodeAB",IWDNode.LEAD_SELECTION).getChildNode("NodeABC",0);
IWDNodeElement element=divNode.createElement();
divNode.addElement(element);
element.setAttributeValue("AttbA","Text");

String text=wdContext.nodeNodeA().getChildNode("NodeAB",IWDNode.LEAD_SELECTION).getChildNode("NodeABC",0).getElementAt(0).getAttributeAsText("AttbA");
wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess(text);

2 Comments