Problem binding list of elements

Hello,

I have two entities (Project and Student), with many to many relathionship and a form with two lists of elements.

When I want to add new student, two list of elements appear. One list (left) have all available projects and other list (right) will have the project selected by the student.

The problem come when I try to bind the right list. I have other examples but with simple elements like this:

getBinder().forField(tfDescription).withConverter(String::trim, String::trim).bind(Project::getDescription, Project::setDescription);

Does anyone know how can I bind a list of elements?

There are several different approaches that might work here. I wouldn’t probably use Binder at all in a scenario like that (typically Binder binds one Field to one Property), but it could be made work with a suitable Converter. Have you already watched this training: https://vaadin.com/training/course/view/v10-forms ?

Thank you for the answer Olli.

I just watch that training but still don’t know how to solve it.

What can I use instead of binder? I don’t find anything that I can use…

Hi,

it depends what your UI component there is. If you have something like a TextField, you can react to its value changes in a ValueChangeListener. This should also have a mention in the training.

-Olli

Hi!

Ok, but the problem is that I have a list of elements to save. Something like this to save “venus, earth, mars” in the list but using vaadin 10: https://vaadin.com/docs/v7/framework/components/components-twincolselect.html

You could display the items in two Grids, for example. Then add two buttons for moving items between the two Grids. On button click, you can then put the selected item inside your object instance or remove it from there.