I have a question -----------------------------------------------

I have a question

-------------------------------------------------------------------------

@RolesAllowed("USER")
@Route(value = "/assignment-builder/", layout = RbacLayout.class)
@CssImport(value = "./styles/styles.css")
public class RbacPurposesBuilderView extends VerticalLayout implements HasUrlParameter<Integer> {
    private UserEntity user = new UserEntity();
    private H1 appTitle = new H1("Назначение:");
    private final AuthPurposesService purposeService;
    private final AuthPermissionService permissionService;
    TwinColSelect<String> purposeSelect = new TwinColSelect<String>();
    private Set<String> previouslySelected;
    private String userId;
    @Autowired
    public RbacPurposesBuilderView(AuthPurposesService purposeService, AuthPermissionService permissionService) {
        this.purposeService = purposeService;
        this.permissionService = permissionService;
    purposeSelect.setItems(permissionService.getValueRolesAndPermissions(userId));
    purposeSelect.setValue(purposeService.getRolesAndPermissions(userId));

    purposeSelect.setLabel("Выберите маршруты");
    purposeSelect.setWidth("900px");
    purposeSelect.setHeight("700px");
    add(appTitle, purposeSelect);
}
@Override
public void setParameter(BeforeEvent event, Integer userId) {
    this.user = purposeService.getUserById(userId);
    appTitle.setText("Назначение: " + user.getUsername());
    this.userId = String.valueOf(userId);
}

}

-----------------------------------------------------------------------------------

purposeSelect.setValue(purposeService.getRolesAndPermissions(userId)); ==>

are not showing in the right side.


Your issue is not specific to TwinColSelect, but would happen with any multiselect component of Vaadin, such as MultiSelectComboBox, CheckBoxGroup, ... The problem is in object equality. The objects returned by this call purposeService.getRolesAndPermissions(userId) are not the same instances than objects included in this set permissionService.getValueRolesAndPermissions(userId).

Thank you for your response. What would be the most correct solution? Matching to the same object? It's just that these two services take data from different tables. 

Set<String> items = permissionService.getValueRolesAndPermissions(this.userId);
purposeSelect.setItems(items);

Set<String> value = purposeService.getRolesAndPermissions(this.userId);
Set<String> result = new HashSet<>(items);
result.retainAll(value);

I solved the problem by filtering the desired entries from the main list.