Own TwinColSelect with ListSelect

Hallo,

i crate my own TwinColSelect mit two ListSelect and four Buttons. I don’t use the Vaadin TwinColSelect because i don’t react for Button Click and the datasource from left side changed at runtime.
The right List only remove items by Botton.

My Problem:
How may I transfer the Item-Caption fom the left site to the right side.
I don’t bind the left ListSelect with a Datasource. I fill it manually.

Here my code to fill the left side (ListSelect)

public void setContainerDatasource(Container jpa, String strId, String strCaption) {
    for (Iterator<?> i = jpa.getItemIds().iterator(); i.hasNext();) {
      Object iid = i.next();
      Item item = jpa.getItem(iid);
      listLeft.addItem(item.getItemProperty(strId).getValue().toString().trim());
      listLeft.setItemCaption(item.getItemProperty(strId).getValue().toString().trim(),
          item.getItemProperty(strCaption).getValue().toString());
    }
  }

The right side is filling by this code by click on the first Button:

[code]
private Object cmdClickAllLeftToRight(ClickEvent event) {
//Container c = listLeft.getContainerDataSource();

List<Object> toAdd = new ArrayList<Object>();
for (Object id : listLeft.getItemIds()) {
  toAdd.add(id);
}

for (Object id : toAdd) {
  listRight.addItem(id);
  [color=#FF0000]


// listRight.setItemCaption ???

[/color]
}
return null;
}
[/code]Is this the correct way to do this?

Thanks
Patrick

Hi,

I wonder, can you just not set the caption on the right list the same way you do it on the left list? That is, read the item from the container and get the container property you want.

Best regards,
Olli

Hallo Oli,

thanks for your fast answer.
It has not succeeded. I want to extract the left Item-Caption to the right. I don’t filling the right side from extern class. Is the caption saved in my object “id” ?

Please give me an example of what you mean.

Thanks
Patrick

Hi,

the Item itself doesn’t contain the caption. You could either read the caption from from the container, like you do when you initialize the left list, or from the left ListSelect object with getItemCaption(itemId). The second option would look something like this:

for (Object id : toAdd) {
      listRight.addItem(id);
      String caption = listLeft.getItemCaption(id);
      listRight.setItemCaption(id, caption);
}

-Olli

Hi Olli,

Great Tip!!!
Thanks for your help.

Patrick