Texterenderer

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?

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);

17434195.png

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.

I uploaded the code to a git repository, so you can test it.

https://github.com/DiegoSanzVi/gridComponentColumn

Hello Diego,

your reply is empty.

I uploaded the code to a git repository, so you can test it.

https://github.com/DiegoSanzVi/gridComponentColumn

Ohhhhh

great

I will test it