SuggestBox Add-on
a suggestbox for vaadin
This is a suggestbox for vaadin, wrapping the gwt suggestbox.
keywords: suggest, autocomplete
for vaadin 7, please use version 1.0.5
Sample code
package com.librishuffle.demo; import com.google.common.collect.ImmutableSet; import com.librishuffle.SuggestBox; import com.librishuffle.shared.SuggestionDto; import com.vaadin.ui.Notification; import java.util.Set; import static com.vaadin.ui.Notification.Type.TRAY_NOTIFICATION; import static java.util.stream.Collectors.toSet; /** * @author Bernd Hopp * @version 1.0 * CitySuggestBox is a sample SuggestBox that will suggest cities on user input * */ public class CitySuggestBox extends SuggestBox{ public CitySuggestBox(){ super("german cities here", 800, 1); } //this is the list of cities that a user can choose from private final Set<SuggestionDto> CITY_SUGGESTIONS = ImmutableSet.of( new SuggestionDto(1, "Berlin"), new SuggestionDto(2, "Bochum"), new SuggestionDto(3, "Hamburg"), new SuggestionDto(4, "München"), new SuggestionDto(5, "Köln") ); @Override protected Set<SuggestionDto> getSuggestions(String query) { final String queryLower = query.toLowerCase(); return CITY_SUGGESTIONS .stream() .filter(suggestion -> suggestion.getDisplayString().toLowerCase().contains(queryLower)) .collect(toSet()); } @Override public void selectionChanged(int itemId) { SuggestionDto citySuggestion = CITY_SUGGESTIONS .stream() .filter(suggestion -> suggestion.getItemId() == itemId) .findFirst() .get(); Notification.show("selected " + citySuggestion.getDisplayString(), TRAY_NOTIFICATION); } }
Links
Compatibility
Was this helpful? Need more help?
Leave a comment or a question below. You can also join
the chat on Discord or
ask questions on StackOverflow.
Version
- clear input after selection, if wanted ( additional constructor parameter for SuggestBox plus legacy constructor )
- SuggestBox constructor parameter documentation
- parameter check fix, minLength must be at least 1, not 0
- Released
- 2016-01-11
- Maturity
- STABLE
- License
- Apache License 2.0
Compatibility
- Framework
- Vaadin 7.6+
- Vaadin 8.0+ in 2.0.0
- Browser
- N/A
SuggestBox Add-on - Vaadin Add-on Directory
a suggestbox for vaadinSuggestBox Add-on version 1.0.0
null
SuggestBox Add-on version 1.0.1
minor fixes, some doc improvement
SuggestBox Add-on version 1.0.2
null
SuggestBox Add-on version 1.0.3
null
SuggestBox Add-on version 1.0.4
some minor fixes
SuggestBox Add-on version 1.0.5
- clear input after selection, if wanted ( additional constructor parameter for SuggestBox plus legacy constructor )
- SuggestBox constructor parameter documentation
- parameter check fix, minLength must be at least 1, not 0
SuggestBox Add-on version 2.0.0
compiled for vaadin 8, updated dependencies