I am using JSF custom validator to fetch an error message from proper resource bundle.
The syntax used is
<myCustom:regexValidator regex="^[a-zA-Z0-9_\\/\-\. ]*$"
validationMessage="#{resourceBundle['name.format.error']}" />
Now what happens is, the error message returned is always fetched from Messages_en_US.properties file.
How do I fetch the mess开发者_StackOverflowage from Messages_ar_AE.properties file? Is there a place where i need to set the Locale, for the application to identify the correct Resource Bundle file?
Thanks.
As I was using Spring and JSF, the statment
<myCustom:regexValidator regex="^[a-zA-Z0-9_\\/\-\. ]*$"
validationMessage="#{resourceBundle['name.format.error']}" />
Spring Framework would look for the key 'name.format.error' in messages.properties file defined in the classpath; As by default the locale is identified as English, unless changed otherwise using LocaleResolver.
To fetch the message from appropriate resource bundle the locale has to be set in 'org.springframework.web.servlet.LocaleResolver' setLocale method
This would help Spring framework point to appropriate resource bundle.
Thanks.
精彩评论