Hi,
I have a bit of a problem with my Validator class. It is returning error strings with part of the message in Spanish, and part of it in English..
messageSource bean definition:
Code:<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basenames" > <list> <value>WEB-INF/content/messages</value> <value>WEB-INF/content/validations</value> </list> </property> <property name="fallbackToSystemLocale" value="false"></property> </bean>I have a function that will load fieldLabel variables:Code:public class ModelXValidator implements Validator{ private final String DEFAULT_MESSAGE= "Default Message"; private String format = "dd/M/yyyy"; @Autowired private MessageSource messageSource; private String fieldlabelPhone; ... }
Then I'll use the fieldLabelPhone value in the following manner:Code:public void setFieldLabelsX() { this.fieldlabelPhone= messageSource.getMessage("fieldlabel.general.phone",null,null); }
My expectation is for it to return:Code:public void validateStart(BusinessProfile business, Errors errors) { //phone if(GenericValidator.isBlankOrNull(business.getContactInformation().getPhoneNumber())) errors.rejectValue("contactInformation.phoneNumber","general.validation.field.required", new Object[] {fieldlabelPhone}, DEFAULT_MESSAGE); ... }
Teléfono es requerido. (Spanish, default)
Phone Number is required. (English)
However, it's returning: "Phone es requerido." (a mix of Spanish and English) when the locale is Spanish. That is because messageSource.getMessage("fieldlabel.general.phone ",null,null); is returning an english String. Yet, the English locale works like a charm.
Is there any way to access the locale inside a Validator class so that I can pass it on to the messageSource? Why does it return the proper error message (spanish) but not the proper field label String?
thanks,
del


Reply With Quote