Created
January 26, 2023 16:52
-
-
Save mstahv/05d3ae2142185de86bfac1ed84b03628 to your computer and use it in GitHub Desktop.
Abusing Vaadin ComboBox lazy data binding for filtering other components using ComboBox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ArrayList<String> values = new ArrayList<>(); | |
values.add("foo"); | |
values.add("bar"); | |
ComboBox<String> stringComboBox = new ComboBox<>(); | |
stringComboBox.setItemsWithFilterConverter((CallbackDataProvider.FetchCallback<String, String>) query -> { | |
if(query.getFilter().isPresent()) { | |
String filter = query.getFilter().get(); | |
System.out.println("Do something else with filter: " + filter); | |
return values.stream() | |
.filter(s -> s.startsWith(filter.toString())) | |
.skip(query.getOffset()).limit(query.getPageSize()); | |
} | |
return values.stream().skip(query.getOffset()).limit(query.getPageSize()); | |
}, s -> s); | |
stringComboBox.addValueChangeListener(v -> { | |
// Selecting existing values | |
}); | |
stringComboBox.addCustomValueSetListener(v -> { | |
// adding new values (probably all intercepted already in lazy data binding) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment