cancel
Showing results for 
Search instead for 
Did you mean: 

Context Node Attribute Binding

Former Member
0 Kudos

Hi All,

I have the following scenario on the context of the view:

- Node 1 (Model Node)

- Model Atttribute(Attribute 11)

- Node 2 (Value Node)

- Value Attribute(Attribute 21)

I would like to get the value of Attribute 21 on Node 2 and put it in Attribute 11 of Node 1.

I tried the following:

wdContext.currentNode1_InputElement().Attribute11(wdContext.currentNode2Element().getAttribute21());

but at run time i got: java.lang.NullPointerException.

any idea!

thanks,

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

HI,

I believe you want to give inputs in a node to an RFC.

you have got values in your Node 2. You want to pick it up and pass it to the Node 1.

<RFCname>_input input = new <RFCname>_input();

wdContext.Node<MainNode>().bind(input);

now the RFC element is created.now you will be able to pass the data to the direct import parameters.

If you want to pass data through the table structure,

you again have to declare the structure and bind it to the node.

<TableStructure> str = new <TableStructure>();

str.setVal1();

str.setVal2();

wdContext.current<RFC>element().set<TableStructure>(str)

AM

Answers (6)

Answers (6)

Former Member
0 Kudos

Hi,

Check whether the Node1_Input is null.

Remember that the current<NodeElement> method access the lead selected node element. If your node is empty then a null pointer exception is raised as is in your case.

Beforfe using the current check whether the node is null or has a size greater than zero.

In web dynpro the node having a cardinality of 0...1 and 0...n by default do not have a node element.

Hence, you will have to create an element and add it to the node.

In case the cardinality is 1...n or 1..1 then the node starts with a single element.

Use the cardinality according to requirements.

Regards,

Kartikaye

Former Member
0 Kudos

hi

get the value from the attribute from the Node1

String abc = wdcontext.node<Node2>.currentNode2element.getAttribute21();

IPrivate<viewname>.Icontextelement element = wdcontext.node<Node1>.createelement();

element.setattribute1(abc);

wdcontext.node<node1>.addelement(element);

Former Member
0 Kudos

Hi Rami Z

First: probably your the code that you have posted is wrong:

wdContext.currentNode1_InputElement().Attribute11...

The right way id:

wdContext.currentNode1_InputElement().setAttribute11...

Second: you have this error because the node Node1 don't exist any element yet.

Try to create it first:

INode1_InputElement element = wdContext.currentNode1_InputElement().createNode1_InputElement();
element.setAttribute11(ATTRIBUTE_VALUE_OF_YOUR_OTHER_NODE);

or try to change the collection cardinality of Node to minimun 1, like 1..1 or 1..n.

Marcos

Former Member
0 Kudos

Hi,

Hi first check size of Node1 & Node2: If there are no elements then if you try to access current element It will throw null pointer exception.

if(wdContext.node1().size()>0 && wdContext.node2().size()>0)
{
wdContext.currentNode2Element().getAttribute21(wdContext.currentNode1_InputElement().Attribute11();)
}

Regards,

Charan

Former Member
0 Kudos

Hi,

This is the sample code which may full fill your requirements.

here wa is the model node and Project is the value node.

Zup_Allmstr_Input inputp=new Zup_Allmstr_Input();
		inputp.setMstr("PROJ");
		wdContext.nodeZup_Allmstr_Input().bind(inputp);
		wdContext.currentZup_Allmstr_InputElement().modelObject().execute();

for(int i=0;i<wdContext.nodeWa().size();i++)
		{
			IPrivateLoginView.IWaElement elewa= wdContext.nodeWa().getWaElementAt(i);
			IPrivateLoginView.IProjectElement proele=wdContext.createProjectElement();
			proele.setProject(elewa.getDescr());
			proele.setProjectid(elewa.getId());
			wdContext.nodeProject().addElement(proele);
		}

Regards,

H.V.Swathi

pravesh_verma
Active Contributor
0 Kudos

Hi Rami,

Just check whether there are node elements in the node which you are rtying to access. The nullpointer simply means that either the size of Node1_Input is 0 OR the size of Node2 is 0.

Just do one check of null value for these nodes and then set the value. use this code:


 if(wdContext.nodeNode1_Input()!=null && wdContext.nodeNode1_Input().size>0){
		 if(wdContext.nodeNode2()!=null && wdContext.nodeNode2().size>0){
			 wdContext.currentNode1_InputElement().setAttribute11(wdContext.currentNode2Element().getAttribute21);
		 }
	 }

Thanks and Regards

Pravesh