cancel
Showing results for 
Search instead for 
Did you mean: 

Context Problem (Two ItemListBoxes with Multi Selection)

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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.

roberto_tagliento
Active Contributor
0 Kudos

IPublic$YOUR_CLASS$.I$YOUR_ELEMENT$ YEl;

YEl = wdContext.node$YOUR_NODE$().create$YOUR_ELEMENT$Element();

YEl.setAttr1("XXXXX");

YEl.setAttr1("YYYYY");

wdContext.node$YOUR_NODE$().addElement(YEl);

Former Member
0 Kudos

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

http://www.sam-solutions.net

Answers (3)

Answers (3)

Former Member
0 Kudos

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.

Former Member
0 Kudos

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)

Former Member
0 Kudos

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

http://www.sam-solutions.net

roberto_tagliento
Active Contributor
0 Kudos

Look:

https://media.sdn.sap.com/javadocs/NW04/SPS15/wd/com/sap/tc/webdynpro/progmodel/api/WDCopyService.ht...

/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

Former Member
0 Kudos

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

http://www.sam-solutions.net

Message was edited by: Valery Silaev