hans-georg1
(hans-georg gloeckler)
1
I have two entities, user and role
user
- id
- name
- comment
- relation to role
role
- id
- rolename
- comment
I have now a grid where i want to show for every user in a Combobox cbxRole the rolename.
The cbxRole represent the entries of role
List<Role> list = service.getDAO().findAll();
ComboBox<Role> cbxRole = new ComboBox<>();
cbxRole.setItems(list);
cbxRole.setItemLabelGenerator(Role::getRolename);
In Vaadin 8 it works with the following code:
grid.addColumn(User::getRole).setRenderer(role -> role != null ? role.getRolename() : null, new TextRenderer()).setEditorComponent(cbxRole, User::setRole);
How can i make this in Vaadin 12?
Diego159
(Diego Sanz Villafruela)
2
Hello hans-georg,
have you tried to use addComponentColumn
?
Grid<Person> grid = new Grid<>();
grid.addColumn(Person::getName).setHeader("name");
grid.addColumn(Person::getAge).setHeader("age");
grid.addComponentColumn(person -> {
ComboBox<Person.Role> comboBox = new ComboBox<>("Role", Person.Role.values());
comboBox.setValue(person.getRole());
return comboBox;
}).setHeader("Role");
grid.setItems(new Person("Person 1", 99, Person.Role.ADMIN), new Person("Person 2", 1111),
new Person("Person 3", 1));
add(grid);

hans-georg1
(hans-georg gloeckler)
3
Thanks for your reply.
When i use:
grid.addComponentColumn(person -> {
});
I get the following error:
The method addComponentColumn(ValueProvider<Person,V>) in the type Grid<Person> is not applicable for the arguments ((<no type> person) -> {}
But i want this what you have sent me by Picture.
Diego159
(Diego Sanz Villafruela)
4
I uploaded the code to a git repository, so you can test it.
https://github.com/DiegoSanzVi/gridComponentColumn
Diego159
(Diego Sanz Villafruela)
6
I uploaded the code to a git repository, so you can test it.
https://github.com/DiegoSanzVi/gridComponentColumn