on 05-24-2005 10:37 AM
Hi all,
I'd like to copy values from one node to another. Both sublying models are similar, but different types (one is bapitrvreo type and the other is ptrv_receipts).
However, most of the fields are the same (same name and same type).
I've found out this interesting method copyCorresponding, from WDCopyService class, but I don't understand how can I use it...
Here is a piece of my code that is working, but not really good:
Ptrv_Receipts receipt = new Ptrv_Receipts();
receipt.setExp_Type(wdContext.currentReceiptsElement().modelObject().getExp_Type());
receipt.setRec_Amount(wdContext.currentReceiptsElement().modelObject().getRec_Amount());
receipt.setRec_Curr(wdContext.currentReceiptsElement().modelObject().getRec_Curr());
receipt.setRec_Date(wdContext.currentReceiptsElement().modelObject().getRec_Date());
receipt.setRec_Refnr(wdContext.currentReceiptsElement().modelObject().getRec_Refnr());
receipt.setRec_Rate(wdContext.currentReceiptsElement().modelObject().getRec_Rate());
receipt.setShorttxt(wdContext.currentReceiptsElement().modelObject().getShorttxt());
And here is what I'd like to do, if possible:
Ptrv_Receipts receipt = new Ptrv_Receipts();
WDCopyService.copyCorresponding(receipt, wdContext.currentReceiptsElement().modelObject());
Thanks for any help,
Caroline
Hi
u can usae wdCopy Service Method but the node u r copyin to shuld contain the same structure of the Source Node.
please check that
The Source Node and destination Node shuld contain the same no of Value Attributes.
The Value Attributes Names shuld also be the same
Here is following Example
WDCopyService.copyElements(wdContext.node<<Source>>(),wdContext.node<<Dest>>);
Hope this shuld help u
With Wishes
Krishna kanth
Message was edited by: krish kanth
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks to both of you for your anwers...
If I understand well, you mean that it's not possible to use copyservice to copy one node to another if I have the following structure:
node1
- attr1
- attr2
- attr4
node2
- attr1
- attr3
- attr4
I thought WDCopyService would be able to copy matching attributes from one node to the other (kind of reflexion system).
Do you have any advice on how to do such a copy in that case ?
From documentation:<i>
The method inspects all attributes of source, searches a compatible attribute in target and copies the value if it finds one. Values are considered compatible if their Java class matches:
- All numeric classes (Byte, Short, Integer, Long, Float, Double, BigInteger and BigDecimal) and primitives (byte, short, int, long, float, double) are compatible.
- Boolean class and primitive are compatible.
- Character (class) and char (primitive) are compatible.
- Otherwise source and target attribute must be based on the same class.</i>
So, as far as I understand, your model attributes have the same name but brokes type compatibility?
VS
Hi Caroline,
Everything is done for you in the class you just mentionned (WDCopyService), just check how to use it in the hehp within your IDE...
Otherwise for quick help:
// this code copy one element into another one with all attributes of course.
// the newElementInserted has to be an existing element of course.
WDCopyService.copyCorresponding(elementFrom,newElementInserted);
// you can use also this beautifull class, this one use sub folder copy and copy all sub nodes
WDCopyService.copySubtree()
I hope it will help you
Best regards,
Emmanuel.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
92 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.