Skip to Content
author's profile photo Former Member
Former Member

Context Problem (Two ItemListBoxes with Multi Selection)

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 24, 2006 at 07:07 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 24, 2006 at 07:14 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 24, 2006 at 01:28 PM

    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)

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 24, 2006 at 10:02 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.