How to handle combobox captions of type Enum

Another title could be “how to externalize combobox captions of type Enum”, but I’m not focusing on externalising strings (i18n) but trying to find the correct method for showing the item captions.

Let’s go with an example.
I’ve the following Enum:

public enum EnumContactAction {

BLANK ("")
private String _value;

private EnumContactAction(String value){
this._value = value;

public String getValue() {
return this._value;

public static String getCaption( EnumContactAction input ) {

switch (input){
case MAIL:
return "Email address";
case PHONE:
return "Telephone number";
return "Twitter account";
return "";

As you can see it has a static method getCaption for getting the correct captions, there I should put the externalization stuff using i18n common tools.

I’ve added the Enum into a “new Vaadin 8 Project”.

The changed init method of the MyUi class is:

protected void init(VaadinRequest vaadinRequest) {
final VerticalLayout layout = new VerticalLayout();

// new Vaadin 8 combobox definition
ComboBox<EnumContactAction> cb = new ComboBox<EnumContactAction>();

// just setting the combobox size using some java 8 trick, you can disregards it
cb.setWidth( EnumSet.allOf(EnumContactAction.class).stream()

// get all values from enumerator and put them in combobox

// combobox item must be selected (BLANK value handle the lack of real value)

// preset to the blan value in ordr to avoid the 'null' value

// here is where the captions in the combobox are handled

Button button = new Button("Click Me");
button.addClickListener(e -> {
layout.addComponent(new Label("Choosen value: '" + EnumContactAction.getCaption(cb.getValue())
+ "', and this is the internal enum value: '" + cb.getValue() + "'"));

layout.addComponents(cb, button);


This is how I’m using a combobox linked to a enumerator.
It’s working, but am i doing right? Can it be improved?

Can any of the Vaadin/java guru presenti in the forum answer?

is the complete sample.

Currently I’m having trouble rending that enum into a grid, but this is another issue, I’ll write it in another thread.


Let’s start by saying that I’m not a Vaadin Guru (40% success on last vaadin certification).

I use java bundle to translate enum in to labels. Bundle is configured and loaded by spring with

Then I write a method somewhere, better if static, to translate a key in to label with given locale, something like:

Translator.translate(String key, Locale loc) I use Enum name to build labels this way:

public static String getCaption( EnumContactAction input, Locale loc ) { return Translator.translate("my.prefix.", loc); } I think you can make getCaption not static.

I hope this can help you.

Thanks Luca (Grazie),
the focus of my post is on Enum and ComboBox, not text externalization (bundle and so on).