Directory

← Back

SuggestBox Add-on

a suggestbox for vaadin

Author

Rating

Popularity

<100

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

Compatibility

(Loading compatibility data...)

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

compiled for vaadin 8, updated dependencies

Released
2017-04-28
Maturity
STABLE
License
Apache License 2.0

Compatibility

Framework
Vaadin 8.0+
Vaadin 7.6+ in 1.0.5
Browser
Browser Independent

SuggestBox Add-on - Vaadin Add-on Directory

a suggestbox for vaadin SuggestBox Add-on - Vaadin Add-on Directory
This is a suggestbox for vaadin, wrapping the gwt suggestbox. keywords: suggest, autocomplete for vaadin 7, please use version 1.0.5
Online