2013-12-13 3 views
1

Я хочу предварительно выбрать элементы в контейнереAllClienteByAsociado, я пытаюсь предварительно выбрать те же элементы в контейнереAllCliente, но также не найден, извините за плохой английский.Как установить выбор по умолчанию в TwinColSelect Vaadin

TwinColSelect colListClientes = new TwinColSelect(); 

private generateColListClientes(Asociado asociadoInstance){ 
    clienteController = new ClienteController(); 

    //Obtenemos el container con los datos 
    BeanItemContainer<Cliente> containerAllCliente = new BeanItemContainer<Cliente>(Cliente.class); 
    containerAllCliente.addAll(clienteController.getCollectionCliente()); 

    BeanItemContainer<Cliente> containerAllClienteByAsociado = new BeanItemContainer<Cliente>(Cliente.class); 
    containerAllClienteByAsociado.addAll(asociadoInstance.getClientes()); 



    colListClientes.setMultiSelect(true); 
    colListClientes.setImmediate(true); 
    colListClientes.setContainerDataSource(containerAllCliente); 
    colListClientes.setLeftColumnCaption("Listado de Clientes"); 
    colListClientes.setRightColumnCaption("Clientes del Asociado"); 
    colListClientes.setMultiSelect(true); 


    for (clienteTotales in containerAllCliente){ 

     colListClientes.setValue(clienteTotales); 

    } 

    return colListClientes; 
} 

ответ

0

Это мое решение, отлично работайте в моем коде.

private generateColListClientes(Asociado asociadoInstance){ 

     clienteController = new ClienteController(); 


     //DEFINITION OF CONTAINERS 
     HashSet<Cliente> containerAllCliente = new HashSet<Cliente>(); 
     containerAllCliente.addAll(clienteController.getCollectionCliente()); 

     HashSet<Cliente> containerAllClienteByAsociado = new HashSet<Cliente>() 
     containerAllClienteByAsociado.addAll(asociadoInstance.getClientes()) 

     //DEFINITION OF TWINCOLUMN 
     colListClientes.setLeftColumnCaption("Listado de Clientes"); 
     colListClientes.setRightColumnCaption("Clientes del Asociado"); 
     colListClientes.setMultiSelect(true); 
     colListClientes.setWidth("350px"); 
     colListClientes.setImmediate(true); 

     HashSet<Cliente> preselected = new HashSet<Cliente>(); 

     //TOUR TOTAL CLIENTS 
     for (Cliente cliente : containerAllCliente){ 
      colListClientes.addItem(cliente); 
      //WE COMPARE TOTAL CLIENTS TO ASOCIADO.CLIENTES 
      for(Cliente clienteAsociado : containerAllClienteByAsociado) { 
       //COMPARE IDS AND PRESELECT IF IS THE SAME 
       if(cliente.id==clienteAsociado.id){ 
        preselected.add(cliente); 
       } 

      } 
     } 

     colListClientes.setValue(preselected); 



     return colListClientes; 
    } 
0

Вместо использования setValue (...) для каждого элемента просто используйте его один раз и передайте всю коллекцию в качестве аргумента.

При использовании setValue (...) с отдельными элементами он отменяет выбранные ранее значения.

+0

Я пытаюсь использовать этот colListClientes.setValue (containerAllCliente), но не работает – Brumanuel

1

Вместо этого:

`BeanItemContainer<Cliente> containerAllCliente = new BeanItemContainer<Cliente>(Cliente.class);` 

Используйте это:

`BeanContainer<String,Cliente> containerAllCliente = new BeanContainer<String,Cliente>(Cliente.class);` 

Кроме того, при заполнении вашего двойника-выбора, установите его свойство "ID", чтобы быть какой-то идентификации переменной-члена/собственностью Cliente.class

После заполнения, вы можете использовать:

twin-select.setValue(<value of identifying member data of the particular Cliente instance>);

Эта ссылка может оказаться полезным: https://dev.vaadin.com/svn/doc/book-examples/trunk/src/com/vaadin/book/examples/datamodel/BeanContainerExample.java

Я надеюсь, что это помогает.

Смежные вопросы