StringToInteger Converter I18n

I have a TextField in my Vaadin Webapp which is binded to an Integer property. When I try to put a String value inside, Vaadin raise a ConversionException which contains a String value. This value will be display around the box to warn the user that he put a value instead of an Integer. The message says “Could not convert value to Integer”. Everything it’s ok but I need to translate this message.

How I can manage to translate it easily ?

And I think the best way is to use a message key (instead of a string value) and use the ResourceBundle to translate it.

It would be great to know how this could be acomplished.

Any ideas?

Hello Sébastien,

I would suggest you to override the
class and set the new convertor to the textfield.
In the new class override the method as

 public Integer convertToModel(String value,Class<? extends Integer> targetType, Locale locale) throws ConversionException {
       return super.convertToModel(value, targetType, locale);
   }catch(throws ConversionException){
        throw new ConversionException("Your Custom message");

And the other way is to implement textChangeListener/BlurListener and validate if the value entered is an integer or not.


Thank’s for your solutions.

I’ve found a way around to translate my error messages. I’ve created a FieldBuilder that is able to create all Fields available on Vaadin. And in its build method I add the following lines to have translated message:

if (field instanceof DateField) { ((DateField) field).setParseErrorMessage(ApplicationHelper.getMessage("")); } else if (field instanceof AbstractField) { ((AbstractField) field).setConversionError(ApplicationHelper.getMessage("parse.number.conversionexception")); } But I don’t like to use a FieldBuilder for all fields inside my WebApp. It would be easier to have a mechanism inside the Field to have translatable messages when the conversion make exception.


Hello Sébastien,

I ran in to
link, I think this would be helpful for what you are looking at.


Thank you Krishna. It could be very helpful.

I’ll try this.

field.setConversionError(“your message”);

Hello, I have a simmilar question about this, is there a way to catch this error? I would like to set a error style on the textfield when this happends.