Enums play nicely with ValueListBox

public enum Fruit {
    APPLE ("Apple"),
    BANANA ("Banana"),
    ORANGE ("Orange"),
    MANGO ("Mango");

    private String value;

    Fruit(String value) {
        this.value = value;
    }

    @Override
    public String toString() {
        return value;
    }

    public static Fruit fromString(String value) {
        if (value != null) {
            for (Fruit fruit: Fruit.values()) {
                if (value.equals(fruit.toString())) {
                    return fruit;
                }
            }
        }
        return null;
    }
}


ValueListBox<Fruit> fruitPicker = new ValueListBox<Fruit>(new AbstractRenderer<Fruit>() {
    @Override
    public String render(Fruit object) {
        return object == null ? "" : object.toString();
    }
}
fruitPicker.setAcceptableValues(Arrays.asList(Fruit.values));
This entry was posted in Uncategorised and tagged , , . Bookmark the permalink.

One comment on “Enums play nicely with ValueListBox

  1. Arnaud on said:

    Thanks for this example .. it did work just fine with RequestFactoryEditor !
    I figure out how to make it work with ListBox widget but with no success ..

    I’ll try to get it working with values defined in properties files.

    Thanks a lot !

Leave a Reply

Your email address will not be published. Required fields are marked *

*

2,767 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>