use of org.springframework.context.support.ResourceBundleMessageSource in project spring-mvc-test-examples by pkainulainen.
the class ExampleApplicationContext method messageSource.
@Bean
public MessageSource messageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename(MESSAGE_SOURCE_BASE_NAME);
messageSource.setUseCodeAsDefaultMessage(true);
return messageSource;
}
use of org.springframework.context.support.ResourceBundleMessageSource in project formplayer by dimagi.
the class TestContext method messageSource.
@Bean
public MessageSource messageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("i18n/messages");
messageSource.setUseCodeAsDefaultMessage(true);
return messageSource;
}
use of org.springframework.context.support.ResourceBundleMessageSource in project spring-framework by bluecrow1986.
the class DataBinderTests method testBindingErrors.
@Test
public void testBindingErrors() {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("age", "32x");
binder.bind(pvs);
Errors errors = binder.getBindingResult();
FieldError ageError = errors.getFieldError("age");
assertThat(ageError.getCode()).isEqualTo("typeMismatch");
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("org.springframework.validation.messages1");
String msg = messageSource.getMessage(ageError, Locale.getDefault());
assertThat(msg).isEqualTo("Field age did not have correct type");
messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("org.springframework.validation.messages2");
msg = messageSource.getMessage(ageError, Locale.getDefault());
assertThat(msg).isEqualTo("Field Age did not have correct type");
messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("org.springframework.validation.messages3");
msg = messageSource.getMessage(ageError, Locale.getDefault());
assertThat(msg).isEqualTo("Field Person Age did not have correct type");
}
use of org.springframework.context.support.ResourceBundleMessageSource in project spring-framework by bluecrow1986.
the class ResourceBundleThemeSource method createMessageSource.
/**
* Create a MessageSource for the given basename,
* to be used as MessageSource for the corresponding theme.
* <p>Default implementation creates a ResourceBundleMessageSource.
* for the given basename. A subclass could create a specifically
* configured ReloadableResourceBundleMessageSource, for example.
* @param basename the basename to create a MessageSource for
* @return the MessageSource
* @see org.springframework.context.support.ResourceBundleMessageSource
* @see org.springframework.context.support.ReloadableResourceBundleMessageSource
*/
protected MessageSource createMessageSource(String basename) {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename(basename);
if (this.defaultEncoding != null) {
messageSource.setDefaultEncoding(this.defaultEncoding);
}
if (this.fallbackToSystemLocale != null) {
messageSource.setFallbackToSystemLocale(this.fallbackToSystemLocale);
}
if (this.beanClassLoader != null) {
messageSource.setBeanClassLoader(this.beanClassLoader);
}
return messageSource;
}
use of org.springframework.context.support.ResourceBundleMessageSource in project spring-framework by spring-projects.
the class ResourceBundleThemeSource method createMessageSource.
/**
* Create a MessageSource for the given basename,
* to be used as MessageSource for the corresponding theme.
* <p>Default implementation creates a ResourceBundleMessageSource.
* for the given basename. A subclass could create a specifically
* configured ReloadableResourceBundleMessageSource, for example.
* @param basename the basename to create a MessageSource for
* @return the MessageSource
* @see org.springframework.context.support.ResourceBundleMessageSource
* @see org.springframework.context.support.ReloadableResourceBundleMessageSource
*/
protected MessageSource createMessageSource(String basename) {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename(basename);
if (this.defaultEncoding != null) {
messageSource.setDefaultEncoding(this.defaultEncoding);
}
if (this.fallbackToSystemLocale != null) {
messageSource.setFallbackToSystemLocale(this.fallbackToSystemLocale);
}
if (this.beanClassLoader != null) {
messageSource.setBeanClassLoader(this.beanClassLoader);
}
return messageSource;
}
Aggregations