cancel
Showing results for 
Search instead for 
Did you mean: 

Pass a NodeElement in another component

Former Member
0 Kudos

Hi,

I have a component that has in its context a NodeElement (node with cardinality 1..1, that holds only one element). The NodeElement has an arbitrary number of attributes (of arbitrary types), unknown at design time.

I need to pass this NodeElement from the component (let's call it SourceComp) to another component (let's call it DestinationComp, it's a popup window shown when a method is called). Now, in DestinationComp one attribute (whose name is known) has to be bound to an InputField.

I've tried to pass an IWDNodeElement object to DestinationComp, but the problem is that the binding does not work because the AttributeInfo has a path reference back to SourceComp.

NodeFromPointer: NodeInfo( path=Reportistica/ReportisticaView.SearchProtocolloSAP , class=com.sap.tc.webdynpro.progmodel.context.DataNodeInfo)

(Reportistica is the SourceComp)

So I need a method to make a "mirror" local copy in DestinationComp of the node or a Workaround in order to make the binding work.

Any ideas?

Thank you,

Pietro

Edited by: pietro.m on Sep 15, 2010 3:58 PM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I've found that is possible to copy two nodes or two nodeElements with WDCopyService but in my case it seems it does not work because I can't find in the destinationNode one attribute (I try to get an AttributePointer by specifiying the attribute's name).

Do someone knows if WDCopyService can be used to create a "mirror copy" of one node or nodeElement into an empty destination node or nodeElement?

Thank you

Former Member
0 Kudos

Hi,

You can use WDCopyService. It has different function which you can use to copy node "copySubtree(IWDNode source, IWDNode target)" and to copy elements you can use "copyElements(IWDNode source, IWDNode target)".

Use this [Link|http://help.sap.com/javadocs/NW04S/SPS09/wd/com/sap/tc/webdynpro/progmodel/api/WDCopyService.html] for further details.

Note: Attribute name & type for source and destination node should be exactly same.

Regards,

Manoj

Former Member
0 Kudos

Hi Manoj,

thank you for your answer. The problem is that the component that has to do the "local copy" from the reference to the NodeElement that it gets, does and must not know the internal structure of the element (i.e., number, type and name of attributes).

Hence, I cannot use WDCopyService.

Is there a workaround or a solution for this?

Thank you,

Pietro

Former Member
0 Kudos

Hi,

Ok. But if you don't know about the attributes types and names then you cannot do anything. Atleast if you know name or the element type then you can copy the element but otherwise it seems that it can't be done.

Regards,

Manoj

Former Member
0 Kudos

Hi Manoj,

I have a reference to the original/Source Node. I can get the NodeInfo and get the list of all its attributes.

I'm trying to do something like this in the Destination Component::

	  Iterator<? extends IWDAttributeInfo> iter = MatchcodeRoot.getNodeInfo().iterateAttributes();
	  IWDAttributeInfo currentAttribute;
	  while (iter.hasNext()) {
		  currentAttribute = iter.next();
		  wdContext.nodeMatchcode().getNodeInfo().addAttribute(
				  currentAttribute.getName(), currentAttribute.getDataType());
	  }

Where MatchcodeRoot is the source node (the one that has to be copied) and Matchcode is the destination node (is a node, whose structure is empty - i.e. no attributes specified, with cardinality 1..1 that I've manually created in the context of the destination component).

But this attempt does not seems to work. Do you have any ideas?

Thank you,

Pietro

Edited by: pietro.m on Sep 16, 2010 10:42 AM

Former Member
0 Kudos

Hi,

I have tried to replicate your scenario and it is working fine for me. What is the error which you are getting. Did you try to debug or print some message inside the while loop? I guess iterator is empty.

I have tried with the following code:


Iterator iter = wdContext.nodeNodeA().getNodeInfo().iterateAttributes();
IWDAttributeInfo attrInfo = null;
while(iter.hasNext()) {
    attrInfo = (IWDAttributeInfo)iter.next();
    wdComponentAPI.getMessageManager().reportSuccess("Name"+attrInfo.getName());
    wdComponentAPI.getMessageManager().reportSuccess("Type"+attrInfo.getDataType().getName());
    wdContext.nodeNodeB().getNodeInfo().addAttribute(attrInfo.getName(),attrInfo.getDataType());
}
Iterator iter2 = wdContext.nodeNodeB().getNodeInfo().iterateAttributes();
IWDAttributeInfo attrInfo2 = null;
wdComponentAPI.getMessageManager().reportSuccess("B size"+wdContext.nodeNodeB().getNodeInfo().iterateAttributes().hasNext());
while(iter2.hasNext()) {
    attrInfo2 = (IWDAttributeInfo)iter2.next();
    wdComponentAPI.getMessageManager().reportSuccess("Name"+attrInfo2.getName());
    wdComponentAPI.getMessageManager().reportSuccess("Type"+attrInfo2.getDataType().getName());
}

Here I have node A with two attributes at design time and Node B (cardinality 1..1) with no attributes.

It is adding the attributes successfully and printing the same.

Regards,

Manoj

Former Member
0 Kudos

Now it works... there were two errors:

- the first was an error on the visit of the DestinationNode, that incorrectly showed no attributes

- the second was an error on the code that bound the DestinationNode attribute to a textfield in the DestinationComponent (the error reported was: Attribute 'name' not found)

So I thought that the attribute copy/cloning was failing... D'oh!

Thank you very much for the time you dedicated me,

10 points for you.

See you,

Pietro

Answers (0)