alejandro-du / crudui

Automatically generate CRUD-like Vaadin views for any Java Bean
https://vaadin.com/directory#!addon/crud-ui-add-on
Apache License 2.0
85 stars 54 forks source link

Problem when using the MultiSelectListBox (vaadin) component #114

Closed Shotty1984 closed 12 months ago

Shotty1984 commented 1 year ago

I think me need help, I'm trying to use MultiSelectListBox component in CRUD UI, but I get an error when return multiSelectListBox through FieldProvider.

my test example:

crud.getCrudFormFactory().setFieldProvider("nameGroup", o -> {
    MultiSelectListBox<String> multiSelectListBox = new MultiSelectListBox<>();
    List<String> items = new ArrayList<>(Arrays.asList("group1", "group2", "group3"));
    multiSelectListBox.setItems(items);
    return multiSelectListBox;
});

after return multiSelectListBox:

java.lang.RuntimeException: com.vaadin.flow.data.binder.BindingException: An exception has been thrown inside binding logic for the field element [style='width:100%', multiple='true', readonly='true']

Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class java.util.Set (java.lang.String and java.util.Set are in module java.base of loader 'bootstrap')

When use simple ComboBox work ok, but me needed multiselect combobox :(, What am I doing wrong?

alejandro-du commented 1 year ago

Try returning a Set instead of an ArrayList.

Shotty1984 commented 1 year ago

Try returning a Set instead of an ArrayList.

I figured out a little bit with vaadin and your CRUD UI, thanks for the cool addon, but I have a little problem, maybe I'm doing something wrong again, I need to display the current groups that I pass to multiSelectComboBox.select(currentGroups.subList(0, 3)); but this not work for me :( current groups not show in text line component MultiSelectComboBox.

Current groups but not yet selected: image

My Example:

crud.getCrudFormFactory().setFieldProvider("availableGroups", o -> {
            MultiSelectComboBox<GroupEntity> multiSelectComboBox = new MultiSelectComboBox<>();
            List<GroupEntity> currentGroups = groupService.findAllByIdDomainAndService(idDomain, service);

            multiSelectComboBox.setLabel("Select group");
            multiSelectComboBox.setItems(currentGroups);
            multiSelectComboBox.select(currentGroups.subList(0, 3));
            multiSelectComboBox.setItemLabelGenerator(GroupEntity::getName);

            return multiSelectComboBox;
});

When re-editing element it is necessary, that the groups have already been preselected, It should turn out like this:

image

If follow the documentation V23 (https://vaadin.com/docs/latest/components/multi-select-combo-box#Selection), this should work, but I it doesn't work :( please help me solve the problem.

alejandro-du commented 1 year ago

Are you able to provide a minimal runnable project so I can reproduce the issue?

alejandro-du commented 12 months ago

Closing this. If you still have the issue, please comment and provide more information and details.