cancel
Showing results for 
Search instead for 
Did you mean: 

Transferring a Node with multiple elements

Former Member
0 Kudos

Hi there, Just want to ask the experts out there am I doing the right coding to transfer all elements of a node to another node? Thanks for your guidance!

for (int n =0; n < wdContext.nodeItem().size();n++) {

IPublicDemoWSController.ISa_Item3Element ele = wdContext.nodeSa_Item3().currentSa_Item3Element();

ele.setEMESS(wdContext.nodeItem().getElementAt(n).getAttributeValue("EMESS").toString());

wdContext.currentSa_Item3Element().setITM_NUMBER(wdContext.nodeItem().getElementAt(n).getAttributeValue("ITM_NUMBER").toString());

wdContext.currentSa_Item3Element().setKUNAG(wdContext.nodeItem().getElementAt(n).getAttributeValue("KUNAG").toString());

wdContext.currentSa_Item3Element().setKUNRE(wdContext.nodeItem().getElementAt(n).getAttributeValue("KUNRE").toString());

wdContext.currentSa_Item3Element().setKUNRG(wdContext.nodeItem().getElementAt(n).getAttributeValue("KUNRG").toString());

wdContext.currentSa_Item3Element().setKUNVE(wdContext.nodeItem().getElementAt(n).getAttributeValue("KUNVE").toString());

wdContext.currentSa_Item3Element().setKUNWE(wdContext.nodeItem().getElementAt(n).getAttributeValue("KUNWE").toString());

wdContext.currentSa_Item3Element().setMATERIAL(wdContext.nodeItem().getElementAt(n).getAttributeValue("MATERIAL").toString());

wdContext.currentSa_Item3Element().setPLANT(wdContext.nodeItem().getElementAt(n).getAttributeValue("PLANT").toString());

wdContext.currentSa_Item3Element().setREF_1(wdContext.nodeItem().getElementAt(n).getAttributeValue("REF_1").toString());

wdContext.currentSa_Item3Element().setSALES_UNIT(wdContext.nodeItem().getElementAt(n).getAttributeValue("SALES_UNIT").toString());

wdContext.currentSa_Item3Element().setSHORT_TEXT(wdContext.nodeItem().getElementAt(n).getAttributeValue("SHORT_TEXT").toString());

wdContext.currentSa_Item3Element().setSTORE_LOC(wdContext.nodeItem().getElementAt(n).getAttributeValue("STORE_LOC").toString());

wdContext.currentSa_Item3Element().setTARGET_QTY(wdContext.nodeItem().getElementAt(n).getAttributeValue("TARGET_QTY").toString());

wdContext.currentSa_Item3Element().setTARGET_QU(wdContext.nodeItem().getElementAt(n).getAttributeValue("TARGET_QU").toString());

wdContext.nodeSa_Item3().addElement(wdContext.currentSa_Item3Element());

}

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Jackson,

The issue with your code is that you are using the same current context element instance in the 'for' loop. You need to create new context element instances for each row of data & add it to the context node.

Kind Regards,

Nitin

pravesh_verma
Active Contributor
0 Kudos

Hi Jackson,

I think you are getting confused in the number of ways which are suggested to you! So just to compile it:

1) You can use the CopyElements method of WDCopyService, which will copy elements of one node to another node.

Pre requisite:

1) Both the node Structure including the attributes should be same.

2) Either both of the target and Source node should be Model node OR both should be Value node.

2) You can use the copyCorresponding method of WDCopyService. Read the java Doc for copyCorresponding:


   * The Web Dynpro equivalent for the well know abap feature
   * "MOVE_CORRESPONDING". It intentionally has been renamed because the term
   * "move", although always being used in Cobol and ABAP, is not quite correct
   * and unusual in Java.
   * <p>
   * The method inspects all attributes of <code>source</code>, searches a
   * compatible attribute in <code>target</code> and copies the value if it 
   * finds one. Values are considered compatible if their Java class matches:
   * <ul>
   *   <li> All numeric classes (Byte, Short, Integer, Long, Float, Double,
   *        BigInteger and BigDecimal) and primitives (byte, short, int, long,
   *        float, double) are compatible.
   *   <li> Boolean class and primitive are compatible.
   *   <li> Character (class) and char (primitive) are compatible.
   *   <li> Otherwise source and target attribute must be based on the same class.
   * </ul>
   * <p>
   * Currently, both <code>source</code> and <code>target</code> may be either
   * an {@link IWDNodeElement} or an {@link com.sap.tc.cmi.model.ICMIGenericModelClass}.
   * If any object is of another class, it is simply ignored. These both classes
   * have been chosen, because they can tell about their structure at run time
   * without the need of Java reflection.
   * <p>

3) Explicitly copy the elements using the code, which you have asked in this thread. Again you have to make sure that when you are copying the elements of one node to another then following condition should be met:

i) IWDElement of Source node should not be null. And IWDNode.size() should be > 0.

ii) You should have created the IWDNodeElement of target node before setting the value.

ii) Also take care of datatypes if there are mismatching.

If you take care of all these thigns then your code will definitely work fine.

I hope that helps!

Thanks and Regards

Pravesh

Former Member
0 Kudos

Hey.. Because there is already element in the model node (as I have bind it to a request when the application start), I have changed my logic abit. Now I will use the currentElement first and then only after it is filled, then i will create another element and add it to the node to use it again. LOL pls clarify me if I am doing some funny things because I am trying to do from what I understand and from what you guys advise me:

IPublicDemoWSController.ISa_Item3Element ele;

for (int n = 0; n < wdContext.nodeSa_Item().size(); n++) {

DemoWSOrder model = new DemoWSOrder();

Sa_Item item = new Sa_Item(model);

ele =

(IPublicDemoWSController.ISa_Item3Element) wdContext.nodeSa_Item3().currentSa_Item3Element();

ele.setEMESS(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getEMESS());

ele.setITM_NUMBER(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getITM_NUMBER());

ele.setKUNAG(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNAG());

ele.setKUNRE(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNRE());

ele.setKUNRG(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNRG());

ele.setKUNVE(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNVE());

ele.setKUNWE(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNWE());

ele.setMATERIAL(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getMATERIAL());

ele.setPLANT(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getPLANT());

ele.setREF_1(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getREF_1());

ele.setSALES_UNIT(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getSALES_UNIT());

ele.setSHORT_TEXT(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getSHORT_TEXT());

ele.setSTORE_LOC(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getSTORE_LOC());

ele.setTARGET_QTY(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getTARGET_QTY());

ele.setTARGET_QU(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getTARGET_QU());

ele = (IPublicDemoWSController.ISa_Item3Element) wdContext.nodeSa_Item3().createSa_Item3Element(item);

wdContext.nodeSa_Item3().addElement(ele);

}

Former Member
0 Kudos

Hmmm.. I do not know why..

I am trying to use copyService as below (simply replacing copyService with the huge chunk of codes above), but the thing is after it was exectued with the model, there was no output at all. There is no exception thrown too and the codes is able to run till the end.. hmm.. what could went wrong? I tried displaying the value in both copies.. there were values inside too.

// Copy from model node into model node

WDCopyService.copyElements(wdContext.nodeHeader(), wdContext.nodeHeader3());

// Copy from model node into model node

WDCopyService.copyElements(wdContext.nodeSa_Item(), wdContext.nodeSa_Item3());

pravesh_verma
Active Contributor
0 Kudos

Hi Jackson,

This problem has reallly become very strange now.. :). I guess there is no issues in the code which you have written. However I hope you are using these lines of code for model nodes. That means all these nodes are model nodes.. Right??? As we have already shared you with the the document which shows that this copy service will work in only those cases when both the target and source node are model nodes OR both are value nodes.

Please check it once... I hope this helps!

Regards

Pravesh

Former Member
0 Kudos

Yeah they are all model nodes..

Edited by: Jackson Yap on Mar 16, 2009 10:31 AM

Answers (8)

Answers (8)

Former Member
0 Kudos

Hi Dear,

your code indicating that always node having latest value( ex--always put nth record)

now you can check below code...

for (int n =0; n < wdContext.nodeItem().size();n++) {

IPublicDemoWSController.ISa_Item3Element ele = wdContext.nodeSa_Item3().createSa_Item3Element();

ele.setEMESS(wdContext.nodeItem().getElementAt(n).getAttributeValue("EMESS").toString());

ele.setITM_NUMBER(wdContext.nodeItem().getElementAt(n).getAttributeValue("ITM_NUMBER").toString());

ele.setKUNAG(wdContext.nodeItem().getElementAt(n).getAttributeValue("KUNAG").toString());

ele.setKUNRE(wdContext.nodeItem().getElementAt(n).getAttributeValue("KUNRE").toString());

ele.setKUNRG(wdContext.nodeItem().getElementAt(n).getAttributeValue("KUNRG").toString());

ele.setKUNVE(wdContext.nodeItem().getElementAt(n).getAttributeValue("KUNVE").toString());

ele.setKUNWE(wdContext.nodeItem().getElementAt(n).getAttributeValue("KUNWE").toString());

ele.setMATERIAL(wdContext.nodeItem().getElementAt(n).getAttributeValue("MATERIAL").toString());

ele.setPLANT(wdContext.nodeItem().getElementAt(n).getAttributeValue("PLANT").toString());

ele.setREF_1(wdContext.nodeItem().getElementAt(n).getAttributeValue("REF_1").toString());

ele.setSALES_UNIT(wdContext.nodeItem().getElementAt(n).getAttributeValue("SALES_UNIT").toString());

ele.setSHORT_TEXT(wdContext.nodeItem().getElementAt(n).getAttributeValue("SHORT_TEXT").toString());

ele.setSTORE_LOC(wdContext.nodeItem().getElementAt(n).getAttributeValue("STORE_LOC").toString());

ele.setTARGET_QTY(wdContext.nodeItem().getElementAt(n).getAttributeValue("TARGET_QTY").toString());

ele.setTARGET_QU(wdContext.nodeItem().getElementAt(n).getAttributeValue("TARGET_QU").toString());

wdContext.nodeSa_Item3().addElement(ele);

}

thanks

Jati

Former Member
0 Kudos

Hi there,

I finally modified the code until the following which works. It may be abit long because to cater for the fact that there is already an initialised element in the node. I will be trying the CopyService soon:

for (int n = 0; n < wdContext.nodeSa_Item().size(); n++) {

DemoWSOrder model = new DemoWSOrder();

Sa_Item item = new Sa_Item(model);

if (n==0) {

IPublicDemoWSController.ISa_Item3Element ele =

(IPublicDemoWSController.ISa_Item3Element)

wdContext.nodeSa_Item3().currentSa_Item3Element();

ele.setEMESS(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getEMESS());

ele.setITM_NUMBER(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getITM_NUMBER());

ele.setKUNAG(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNAG());

ele.setKUNRE(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNRE());

ele.setKUNRG(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNRG());

ele.setKUNVE(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNVE());

ele.setKUNWE(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNWE());

ele.setMATERIAL(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getMATERIAL());

ele.setPLANT(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getPLANT());

ele.setREF_1(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getREF_1());

ele.setSALES_UNIT(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getSALES_UNIT());

ele.setSHORT_TEXT(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getSHORT_TEXT());

ele.setSTORE_LOC(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getSTORE_LOC());

ele.setTARGET_QTY(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getTARGET_QTY());

ele.setTARGET_QU(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getTARGET_QU());

} else {

IPublicDemoWSController.ISa_Item3Element ele = (IPublicDemoWSController.ISa_Item3Element) wdContext.nodeSa_Item3().createSa_Item3Element(item);

ele.setEMESS(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getEMESS());

ele.setITM_NUMBER(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getITM_NUMBER());

ele.setKUNAG(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNAG());

ele.setKUNRE(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNRE());

ele.setKUNRG(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNRG());

ele.setKUNVE(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNVE());

ele.setKUNWE(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNWE());

ele.setMATERIAL(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getMATERIAL());

ele.setPLANT(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getPLANT());

ele.setREF_1(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getREF_1());

ele.setSALES_UNIT(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getSALES_UNIT());

ele.setSHORT_TEXT(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getSHORT_TEXT());

ele.setSTORE_LOC(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getSTORE_LOC());

ele.setTARGET_QTY(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getTARGET_QTY());

ele.setTARGET_QU(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getTARGET_QU());

wdContext.nodeSa_Item3().addElement(ele);

}

}

Former Member
0 Kudos

Hi Jackson,

I am not sure your code will work or not as I have not tried like this before.

But atleast one thing is wrong in your above code.

You set all the values of the element 'ele' & then create a new instance before adding to node, so what will be added is an empty row. You have to add it first & then create a new instance.

Kind Regards,

Nitin

Former Member
0 Kudos

Hi there,

Please correct me if I am wrong..

Because I am using currentElement as 'ele', that means it is already added to the node already am I right? That's why what I am doing is assigning values to this currentElement,

THEN

create a new element and add it into the node to be used as next current context for 'ele'.

Former Member
0 Kudos

Hey guys this is the summary of what I am doing so far:

Hi, I am hoping to get some help on this. I am trying to transfer element values from one model Node to another model Node. It sounds simple but maybe I am not really sure of the working of nodes and elements and it is giving me some trouble.

I have bind the model to the context:

Request_Sa_Change request15 = new Request_Sa_Change(model4);

Sa_Change sachange = new Sa_Change(model4);

Sa_Header saheader2 = new Sa_Header(model4);

Sa_Item saitem2 = new Sa_Item(model4);

ArrayOfSa_Item arrayItem = new ArrayOfSa_Item(model4);

arrayItem.addSa_Item(saitem2);

sachange.setHeader(saheader2);

sachange.setItem(arrayItem);

request15.setSa_Change(sachange);

wdContext.nodeRequest_Sa_Change().bind(request15);

Therefore there is already an element being initiated, so I have to set values into this created element before I can create a new one for the next element of values.

From my experiment with the codes below, I find that EVEN after I create and added a new Element into the node, the CurrentNode is still holding the same value of the previous element I create.

This lead me to believe that this is the reason after I execute the model, I got the error "ItemNum is Missing".

for (int n = 0; n < wdContext.nodeSa_Item().size(); n++) {

DemoWSOrder model = new DemoWSOrder();

Sa_Item item = new Sa_Item(model);

IPublicDemoWSController.ISa_Item3Element ele =

(IPublicDemoWSController.ISa_Item3Element) wdContext.nodeSa_Item3().currentSa_Item3Element();

wdComponentAPI.getMessageManager().reportException("" + wdContext.nodeSa_Item3().currentSa_Item3Element().getITM_NUMBER(), true);

ele.setEMESS(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getEMESS());

ele.setITM_NUMBER(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getITM_NUMBER());

ele.setKUNAG(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNAG());

ele.setKUNRE(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNRE());

ele.setKUNRG(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNRG());

ele.setKUNVE(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNVE());

ele.setKUNWE(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNWE());

ele.setMATERIAL(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getMATERIAL());

ele.setPLANT(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getPLANT());

ele.setREF_1(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getREF_1());

ele.setSALES_UNIT(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getSALES_UNIT());

ele.setSHORT_TEXT(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getSHORT_TEXT());

ele.setSTORE_LOC(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getSTORE_LOC());

ele.setTARGET_QTY(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getTARGET_QTY());

ele.setTARGET_QU(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getTARGET_QU());

wdComponentAPI.getMessageManager().reportException("" + wdContext.nodeSa_Item3().currentSa_Item3Element().getITM_NUMBER(), true);

wdComponentAPI.getMessageManager().reportException("before create: " + wdContext.nodeSa_Item3().size(), true);

IPublicDemoWSController.ISa_Item3Element ele2 = (IPublicDemoWSController.ISa_Item3Element) wdContext.nodeSa_Item3().createSa_Item3Element(item);

wdComponentAPI.getMessageManager().reportException("after create: " + wdContext.nodeSa_Item3().size(), true);

wdComponentAPI.getMessageManager().reportException("" + wdContext.nodeSa_Item3().currentSa_Item3Element().getITM_NUMBER(), true);

wdComponentAPI.getMessageManager().reportException("before add: " + wdContext.nodeSa_Item3().size(), true);

wdContext.nodeSa_Item3().addElement(ele2);

wdComponentAPI.getMessageManager().reportException("after add: " + wdContext.nodeSa_Item3().size(), true);

wdComponentAPI.getMessageManager().reportException("" + wdContext.nodeSa_Item3().currentSa_Item3Element().getITM_NUMBER(), true);

}

nikhil_bose
Active Contributor
0 Kudos

// get nodes
IPublicDemoWSController.ISa_Item3Node targetnode = wdContext.nodeISa_Item3();
IPublicDemoWSController.IItemNode sourcenode = wdContext.nodeItem();
// copy elements through WDCopyService
WDCopyService.copyElements( targetnode, sourcenode);

your code


wdContext.nodeSa_Item3().invalidate();
for (int n =0; n < wdContext.nodeItem().size();n++) {
// create new element
IPublicDemoWSController.ISa_Item3Element ele = wdContext.nodeSa_Item3().createSa_Item3Element();
// assign values
ele.setEMESS(wdContext.nodeItem().getElementAt(n).getAttributeValue("EMESS").toString());
wdContext.currentSa_Item3Element().setITM_NUMBER(wdContext.nodeItem().getElementAt(n).getAttributeValue("ITM_NUMBER").toString());
wdContext.currentSa_Item3Element().setKUNAG(wdContext.nodeItem().getElementAt(n).getAttributeValue("KUNAG").toString());
// fill others....

// add element to node
wdContext.nodeSa_Item3().addElement(wdContext.currentSa_Item3Element());

Nikhil

Former Member
0 Kudos

Hi there,

I am trying to make sure the individual copying of elements work first before I try the CopyService.. Hmm someone suggested CopyCorrespond too.. Does both works the same?

Former Member
0 Kudos

Hmmm.. seems like I can't do this?

" for (int n =0; n < wdContext.nodeItem().size();n++) {

IPublicDemoWSController.ISa_Item3Element ele = wdContext.nodeSa_Item3().currentSa_Item3Element();

ele.setEMESS(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getEMESS());

ele.setITM_NUMBER(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getITM_NUMBER());

ele.setKUNAG(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNAG());

ele.setKUNRE(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNRE());

ele.setKUNRG(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNRG());

ele.setKUNVE(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNVE());

ele.setKUNWE(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getKUNWE());

ele.setMATERIAL(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getMATERIAL());

ele.setPLANT(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getPLANT());

ele.setREF_1(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getREF_1());

ele.setSALES_UNIT(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getSALES_UNIT());

ele.setSHORT_TEXT(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getSHORT_TEXT());

ele.setSTORE_LOC(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getSTORE_LOC());

ele.setTARGET_QTY( wdContext.nodeSa_Item().getSa_ItemElementAt(n).getTARGET_QTY());

ele.setTARGET_QU(wdContext.nodeSa_Item().getSa_ItemElementAt(n).getTARGET_QU());

wdContext.nodeSa_Item3().addElement(wdContext.currentSa_Item3Element());

}"

Because it gives this error:

Node(DemoWSController.Request_Sa_Change.Sa_Change.Item3.Sa_Item3): cannot bind or add element, because it is already bound to a node

I am confused.. then how could I transfer nodeItem which can be more than 1?

former_member185086
Active Contributor
0 Kudos

Hello Jackson

I understood that your question regarding transferring value to model node, so that u can execute the model.

modify your code in this way

for (int n =0; n < wdContext.nodeItem().size();n++)
{

 IPrivateTestView.ITestNodeElement  ele1 =  wdContext.nodeTestNode().getTestNodeElementAt(n);*
 ele.setEMESS(ele1.get<value>);*
}

and don't change attribute in this way toString we use when we need string representation of any Object

wdContext.nodeItem().getElementAt(n).getAttributeValue("ITM_NUMBER").toString())

There are simple attribute , Define this in context and bind it to UI.Might these are two many so u are finding workaround

Do one thing

Copy the model node (which u want to transfer ) and paste it in context .rename it and then remove the model binding ,now readymade context node with all proper datatypes .

Best Regards

Satish Kumar

pravesh_verma
Active Contributor
0 Kudos

Hi Satish,

Never use the .size() API in the for loop statement. Always, get the value in some int variable and then use it in for loop.

Simple reason: In the for loop everytime while executing the loop it will calculate the .size() at node which is a performance hit. Instead do like:

int size = wdContext.nodeItem().size();

and then in for loop:


for (int n =0; n < size;n++)
{
 
 IPrivateTestView.ITestNodeElement  ele1 =  wdContext.nodeTestNode().getTestNodeElementAt(n);
 ele.setEMESS(ele1.get<value>);
}

Reagrds

Pravesh

former_member185086
Active Contributor
0 Kudos

Hello Parvesh

Agreed. Thanks for valuable suggestion.I just tried to solve Jackson basic problem ,thats why didn't enter into this much of deep.

Well Its good thanks again.

Best Regards

Satish Kumar

Former Member
0 Kudos

Hi,

Hmm... Old tips to improve performance of BoNodes....

Regards

Ayyapparaj

Former Member
0 Kudos

Hi,

You can use the methods part of WDCopyService for the same

Ex: WDCopyService.copyElements(source, target)

Regards

Ayyapparaj

pravesh_verma
Active Contributor
0 Kudos

Hi Jackson,

In another thread you have asked a question about the copyElements. Just want to clarify, doesnt that worked for you?? But yes if the node structure of both these nodes are not similar then you have to follow this technique only.

If you using this approach then I have a word of advice.

Instead of using this line of code:


ele.setEMESS(wdContext.nodeItem().getElementAt(n).getAttributeValue("EMESS").toString());

You can use easily use:


ele.setEMESS(wdContext.nodeItem().getElementItemAt(n).getEMESS());

Use this technique for all Attributes.

This will solve 2 issues:

1) Everytime entering the name of the attribute manually. NWDS will show the name of the attribute in the help as soon as you press "."

2) Taking care of the conversion of each attribute to String. Doing this will automatically take care of original datatype of the accessed attribute. However even after that you want to change the original datatype then you can do the conversion.

Also I would advice that instead of using following code everytime:


wdContext.nodeItem().getElementAt(n).get...

You can get this element as IWDNodeElement object. and then can use the same element in the all line of code. This make you code more readble and efficient.

like this:


IItemElement eleTemp =  wdContext.nodeItem().getItemElementAt(0);

ele.setEMESS(eleTemp .getEMESS());
...
...
...

so on..

I hope this helps

Thanks and Regards

Pravesh

Former Member
0 Kudos

Hey there,

I couldn't get up to

ele.setEMESS(wdContext.nodeItem().getElementItemAt(n).getEMESS());

I can only reach wdContext.nodeItem().

and the only syntax available next is getElementAt(n).

Former Member
0 Kudos

Hi,

To copy elements from one node to another, please use

WDCopyService.copyCorresponding(

wdContext.<sourcenode>.getElementAt(<lead>),

wdContext.<targetnode>.<targetnode element>);

Jithin

Edited by: jithin james on Mar 13, 2009 6:20 AM

pravesh_verma
Active Contributor
0 Kudos

Hi Jackson,

Sorry for the Typo. Its actually:


ele.setEMESS(wdContext.nodeItem().getItemElementAt(n).getEMESS());

I hope this helps!!

Thanks and Regards

Pravesh

Former Member
0 Kudos

Hi Pravesh,

I did tried to use the CopyService between 2 models. I am amazed that it compile without error because I just discovered there is 1 field additial in the TARGET model. But it still compiles without exception. Then I did a test to see if those fields which are similiar are being copied and indeed it is..

Does it still means the 2 NODEs need to be of the same structure and have same fields?

Former Member
0 Kudos

Thanks!! it looks much nicer now But what a huge chunk of codes! I am still exploring on what you guys say so give me a sec to get it work