Grid SelectionModel pre select row

I’m using Vaadin to build a project at the University.
I use Vaadin 8.5.2 and I tried to pre select some items in a grid.
Code Snipped:

private Grid<User> userGrid;
private MultiSelectionModel<User> selectionModel;
private User currentUser = userService.getUserById(((MainUI)UI.getCurrent()).getCurrentUserId());
List<User> users = userService.getAllUsers();

userGrid = new Grid<>(User.class);
userGrid.setColumns("name", "availability");

selectionModel = (MultiSelectionModel<User>) userGrid.setSelectionMode(SelectionMode.MULTI);

In my oppinion this should work. I also have a selection listener:

userGrid.addSelectionListener(event -> { + " items selected");

And the selection listener said that 1 item is selected but the checkboxes in the UI are all empty.
Please find picture attached.

Do you have any idea on this?

Best and thanks,


Are you using @Push?

No I don’t.
DO I need it? I tested selectAll() and this works.

We annotated @Push(PushMode.MANUAL) at the main UI.

I would recommend automatic push mode instead.

It just occurred to my mind, that in some cases when you call select(), the state is updated yes, but if there is no new activity triggered in UI by user, the change wont be visible before there is activity. You could easily verify this by adding button in UI. If select becomes visible when user click button, it is clear sign that state was correctly updated, and change was is in queue.

If you use automatic push, server will be able to send notification to UI and updates in queue are processed to UI before there is triggering user activity in UI.

Thanks for your Id but I fixed it.
It was a bit easier.
The currentUser is normally a user the the users list but for the selecthionModel it is a different user.
I compared the currentUser with the users in the list and selected the correct user from the list and it worked.

Done :slight_smile: