on 10-24-2006 1:23 AM
People, I really could use some help over here, thanks in advance.
I have two itemlistboxes (which can be multi selected) and need, in an action, to put the selected items of one into the other.
One is bound to a model node which results come from a RFC connection, and this is working well.
The other one is bound to a model node with the same type of the first one, and I want to put elements dinamically in it.
I´m using the following code:
for ( int j = 0, n = wdContext.myNode().size(); j < n; j++ )
{
if (wdContext.Mynode().isMultiSelected(j))
{
IWDNodeElement element = wdContext.Mynode().getElementAt(j);
wdContext.Mynode().removeElement(element);
wdContext.nodeGrpItems().addElement(element);
}
}
With this code (and with many others I tried), I get a conversion error (or a "incompatible nodes" message, when I try to use WDCopyService).
I´m really, really stuck here... So, if anyone can tell me what I´m doing wrong OR explain me another way to do what I want, I´ll be very thankful.
I tried creating a new element and binding it after giving the attributes the right values, my problem was that method createElement with no parameters throws:
java.lang.IllegalArgumentException: model object must not be null
I think if I had this one fixed, I could fix it all.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Rodrigo,
What model classes are shown for both source and target nodes in NW IDE (Context Designer tab)??? Please post class names here as they appears in properties.
At least target has model class -- hence the error...
Valery Silaev
SaM Solutions
This problem was solved by Roberto Tagliento. The code line create$YOUR_ELEMENT$Element() Do not return the Exception I mentioned before, like createElement() with this, I could create it and then add to my context.
I´m very, very pleased! You two really helped me over here, thank you two very much.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
At first I would like to thank you very much for your time
But... unfortunatelly, the line
final IWDNodeElement elTarget = target.createElement(elSource.model());
is producing a java.lang.ClassCastException (which is the exception I´m facing all the way).
The only detail I believe could be helpful for those who intend to help me, and it´s not already posted is that one node is not a root node, while the other is. Can this produce any errors? (Yes, I am referencing nodes with the same type in the code, although the source one is populated by a RFC execution)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Rodrigo,
Are both of your nodes in fact model nodes? Or one is model and other is value? If "yes", are both have same model class?
If you have one model node and other value node, or model classes are different, then you have to use createElement without parameters and copy attributes manually.
Valery Silaev
SaM Solutions
Look:
/people/valery.silaev/blog/2006/07/12/when-wdcopyservice-is-not-enough
/people/sap.user72/blog/2005/11/16/keep-your-webdynpro-node-mappings-simple
Rodrigo,
General hint for node processing: if you are adding elements iterate from firt to last, when you are removing -- iterate from last to first. Your code should work this way:
final IPrivate<ControllerName>IMyNode source
= wdContext.myNode();
final IPrivate<ControllerName>IGrpItems target
= wdContext.nodeGrpItems();
final int size = source.size();
for ( int j = size - 1, j >= 0; j-- )
{
if (source.isMultiSelected(j))
{
final IWDNodeElement elSource = source.getElementAt(j);
source.removeElement(element);
final IWDNodeElement elTarget = target.createElement(<u>elSource.model()</u>);
target.addElement(elTarget);
}
}
See also underlined code -- if both nodes have same model class, you may just pass model object of origin to target when creting element in target. Never add elements created for node A to node B -- this cause errors.
Valery Silaev
SaM Solutions
Message was edited by: Valery Silaev
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.