akuzma
akuzma

Reputation: 1554

vaadin error indicator and message

I want to make custom message in error indicator using Vaadin, like here: http://vaadin.com/download/book-of-vaadin/vaadin-7/html/img/application/errorindicator-example2.png

My application is multilingual and i want to have different message for the same error depending of chosen language. Is it possible to have different error messages for one error indicator? And if it's possible how to do it?

Upvotes: 1

Views: 1799

Answers (2)

piccarsa
piccarsa

Reputation: 23

Remember to add this code to your component:

myComponent.setConversionError("{1}");

This line of code sets your custom message to the error indicator. Otherwise you'll get this message:

Could not convert to {0}

where {0} is the name of your Converter's PRESENTATION class.

Infact this is the javadoc of the AbstractField.setConversionError(java.lang.String valueConversionError) API-method:

Sets the error that is shown if the field value cannot be converted to the data source type. If {0} is present in the message, it will be replaced by the simple name of the data source type. If {1} is present in the message, it will be replaced by the ConversionException message.

Upvotes: 0

ogzd
ogzd

Reputation: 5692

Using java.util.ResourceBundle will help your i18n issues. Each time when Locale is changed, you need to update your bundle as well. For example;

bundle = ResourceBundle.getBundle("messages", locale);

In order to retrieve error representation from bundle, you can use bundle.getString("error.message")

By doing this, you don't need to update code each time when locale is changed. Only the resource location where the representation strings is switched. For more information, http://docs.oracle.com/javase/tutorial/i18n/resbundle/prepare.html

Upvotes: 1

Related Questions