New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ListBox: Current selection is not visible after reopening a dialog #1038
Comments
any progress on this? |
I could reproduce this issue in version 18.0.5. In version 20.0.6 I couldn't reproduce it, so it worked fine there. However I don't know yet from which version on it is fixed. Debugging The first time the setItems() is called on the ListBox, a new DataProvider is set inside the ListBox instance. With this also a listener on the DataProvider is set up and stored in the field However, when the dialog is closed the first time, and thus the ListBox gets detached, so onDetach() the ListBox removes its The first time onAttach() is called In version 20.0.6 I've noticed, that Possible quick fix One possibility is to extend ListBox like this and use your own ListBox class instead: public class ListBox<T> extends com.vaadin.flow.component.listbox.ListBox<T> {
@Override
protected void onAttach(AttachEvent attachEvent) {
T currentValue = getValue();
super.onAttach(attachEvent);
setValue(currentValue);
}
} So you basically make sure the current selection is restored. Be careful though in value change listeners on the ListBox. Calling setValue() will also trigger registered value change listeners. Calling setValue() as above is a server side value change but fortunately the API allows to distinguish whether the value change is coming from server side or client side: listBox.addValueChangeListener(e -> {
if (e.isFromClient()) {
System.out.println("value change from client"); // solely triggered for client side selection changes
} else {
System.out.println("value change from server"); // e.g. triggered via setValue() inside onAttach()
}
}); |
Confirmed this to work with all the supported Vaadin versions. Closing. Please let us know if you'll face this issue again. |
After closing and reopen the dialog again the selection-icon is not visible anymore.
Tested with: vaadin 18.0.5
The text was updated successfully, but these errors were encountered: