cancel
Showing results for 
Search instead for 
Did you mean: 

Nested Node structure in context

former_member205363
Contributor
0 Kudos

Hi Experts,

I have nested node structure in context. Please let me know how to populate nodes with the values and how to retriev values.

NodeA inside NodeB inside attribute text.

Regards,

Lakshmi Prasad.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Dear Laxmi,

Is your subnode (NodeB) singleton or a non-singleton node?

Warm Regards

Upendra Agrawal

former_member205363
Contributor
0 Kudos

Hi Upendra,

Thank you for reply,

NodeA and NodeB both are Singleton Nodes.

Regards,

Lakshmi Prasad.

Former Member
0 Kudos

Dear Lakshmi,

I am having trouble to post this messaage in single post, so I have divided it into three Post

<<<<<<1>>>>>>

Populating the Nested Nodes(Singleton)

Assuming the structure of your context as :


Context
 |+--NodeA
      +--Attribute1
      +--Attribute2
      |+--NodeB
           +--SubAttribute1

Let us assume that we have to add two elements to the node NodeA and the three elements to node NodeB depending on which elements in NodeA is selected.

Basiclly, you have code in two methods :

1. wdDoint() , which would be called at conroller initialization and,

2 supplyNodeB() , use this supplyFunction to your subnode(NodeB) for populating the values w.r.t. to your NodeA.

The WebDynpro Framework will call it automatically every time the contents in the NodeA are changed.

1.wdDoint()-


public void wdDoInit()
  {
    //@@begin wdDoInit()
         // Create two new NodeA elements
             INodeAElement nodeAe1 = wdContext.createNodeAElement() ;
             INodeAElement nodeAe2 = wdContext.createNodeAElement() ;
	       
         //	 Populate NodeA elements
              nodeAe1.setAttribute1("My value 1") ;
              nodeAe1.setAttribute2("My value 2") ;
              
              nodeAe2.setAttribute1("My value 1") ;
              nodeAe2.setAttribute2("My value 2") ;
			  
              wdContext.nodeNodeA().addElement(nodeAe1);
              wdContext.nodeNodeA().addElement(nodeAe1);

    //@@end
  }

Former Member
0 Kudos

<<<<<<2>>>>>>


public void supplyNodeB(IPrivateYourView.INodeBNode node,IPrivateYourView.INodeAElement parentElement)
  {
    //@@begin supplyNodeB(IWDNode,IWDNodeElement)
	// Create three new NodeB elements
	INodeBElement nodeBe1 = wdContext.createNodeBElement() ;
	INodeBElement nodeBe2 = wdContext.createNodeBElement() ;
	INodeBElement nodeBe3 = wdContext.createNodeBElement() ;
			
	// Populate NodeB elements based on the selected NodeA element
	switch (parentElement.getAttribute1()) {
		case 10 :
		nodeBe1.setSubAttribute1("10 Selected 1") ;
		nodeBe2.setSubAttribute1("10 Selected 2") ;
		nodeBe3.setSubAttribute1("10 Selected 3") ;
		
		node.addElement(nodeBe1) ;
		node.addElement(nodeBe2) ;
		node.addElement(nodeBe3) ;
			break;
		case 20 :
		nodeBe1.setSubAttribute1("20 Selected 1") ;
		nodeBe2.setSubAttribute1("20 Selected 2") ;
		nodeBe3.setSubAttribute1("20 Selected 3") ;
		
		node.addElement(nodeBe1) ;
		node.addElement(nodeBe2) ;
		node.addElement(nodeBe3) ;	
			break;

		default :
			break;
	}	
    
    //@@end
  }

Former Member
0 Kudos

<<<<<<3>>>>>>

Accessing the nested node

NodeB is a singleton node, we can access it with the generic context API


	          
//            Get the child node NodeB with the generic context API
              IWDNode  naNode = wdContext.getChildNode("NodeA",0);
              
//            Set the Lead Selection of node NodeA
              naNode.setLeadSelection(<element_number>);
              IWDNodeElement naE1 = naNode.getCurrentElement();
              
//            Get the attribute's value of the current NodeA element
              String text = naE1.getAttributeAsText("Attribute1") ;     
//            Get instance of NodeB that belongs to this NodeA element 
//            Call to getChildNode() will automatically trigger the 
//            execution of supply function      

IWDNode  nbNode = naNode.getChildNode("NodeB" , naNode.getLeadSelection()) ;
//Loop around all the elements in node NodeB
for (int i = 0; i < nbNode.size; i++) {
	// Get current NodeB element
	IWDNodeElement nbE1 = nbNode.getElementAt();
	//You have successfully accessed the Nested Node
	
}

Hope it helps!!

Warm Regards

Upendra Agrawal

former_member205363
Contributor
0 Kudos

Hi Upendra,

Thanks for the reply, I am trying this way and get back to you

former_member205363
Contributor
0 Kudos

Hi Upendra,

This code is not working fine, but I am able to send the data to supply.

Please let me know how to get the values in supply function.

supply(childNode, parentElement)

childNod.getElementAt(0)

here I am getting null, how to get row data.

Regards,

Lakshmi Prasad.

Former Member
0 Kudos

Dear Lakshmi,

Obviously, you should get the null.

Why are you accessing the child node data in supply function.

Here, you have to supply the data to child node.

Warm Regards

Upendra Agrawal

former_member205363
Contributor
0 Kudos

Hi Upendra,

You are correct.

My requirement is like this,

NodeA

-


NodeB

-


Text

I would require to read the NodeB node values and store it in another context node.

NodeA and NodeB are singleton.

At Runtime NodeA is multiple Elements and NodeB is single element.

Regards,

Lakshmi Prasad.

Former Member
0 Kudos

Dear Lashmi,

Are you using a table UI to display the contents of NodeA

If yes then you can write this code at the onLeadSelect Action of Table UI.


IWDNode  naNode = wdContext.getChildNode("NodeA",0);
IWDNode  nbNode = naNode.getChildNode("NodeB" , naNode.getLeadSelection()) ;
IWDNodeElement nbE1 = nbNode.getElementAt(0);

Now in nbE1 you have the required values which you can set to your another context node .

Hope it helps!!

Warm Regards

former_member205363
Contributor
0 Kudos

Hi Upendra,

I written the following code, but I am getting null nbNode.

IWDNode nbNode = wdContext.nodeMDM_LOCATION_DATA().getChildNode("MDM_FLAG_FOR_DEL_rem_retr_plant" , wdContext.nodeMDM_LOCATION_DATA().getLeadSelection()) ;

IWDNodeElement nbE1 = nbNode.getElementAt(0);

Regards,

Lakshmi Prasad.

Former Member
0 Kudos

Dear Lakshmi,

Have you populated your NodeA & NodeB??

Also try this,

Bind your NodeA & NodeB with two Table UI's.

Now for each selected row in the NodeATable Ui you will have a diffrent value in NodeBTable Ui .

This confirms that your supply funtion is working fine. And the code which I provided you should work.

But if you are not getting the values in the NodeBTable UI corresponding to the value of NodeATable UI then there is a problem with your supply function.

Kindly check.

Warm Regards

Upendra Agrawal

former_member205363
Contributor
0 Kudos

Hi Upendra,

I have tested by creating two tables with NodaA and NodeB.

I am getting message which is written in supply function if I select any row from tableA, but values I am not able to retrieve.

TableB is not populating with the values.

Can you do a favour, take two nodes A, B and try to insert and read the data in NodeB.

NodeA (singleton) Cardinality 0..n

-


dataA

-


NodeB(Singleton) cardinality 0..1

-


dataB

User can't select any value manually in TableA(NodaA).

Regards,

Lakshmi Prasad.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Lakshmi,

I believe you need to keep the inner node's singleton property as false so that the inner node can carry elements for various elements of outer node.

Once you create an element for outer node, create elements of the inner node for that created element of the inner node to maintain the heirarchy in a proper fashion.

Let me show.

Let the structure be

Vn_NdA(node)

--Va_Attr1(attribute)

--Vn_NdB(node)

--Va_Attr2(attribute)

You can use the following code for populating both the nodes.

IPrivate<YourView>.IVn_NdAElement Aele = null;

Aele = wdContext.createVn_NdAElement();

Aele.setVa_Attr1("xyz");

wdContext.nodeVn_NdA().addElement(Aele);

IPrivate<YourView>.IVn_NdBElement Bele = null;

Bele = Aele.createVn_NdBElement();

Bele = Aele.setVa_Attr2("abc");

wdConext.nodeVn_NdB().addElement(Bele);

Similarly, you can access each of the element of Outer Node and then get the inner node and the elements within.

wdConext.nodeVn_NdA().getVn_NdAElementAt(0).nodeVn_NdB().getVn_NdBElementAt(0).getVa_Attr2();

Regards,

Tushar Sinha