spring - How to set List of java.util.Locale in Spring XML? -


how can configure list of java.util.locale in spring xml?

this tried (which didn't work..):-

<bean     class="x.y.z.commandbean"     scope="prototype">     <property name="locales">         <list value-type="java.util.locale">             <value>locale.us</value>             <value>locale.fr</value>         </list>     </property> </bean> 

exception :-

 org.springframework.beans.typemismatchexception: failed convert value of type 'java.lang.string' required type 'java.util.locale'; 

also, there way can move locale comma separated values in .properties file?

specifying values

<value>java.util.locale.us</value> <value>java.util.locale.fr</value> 

should trick. getting them properties value seems bit more work.

you specify them like

my.app.locales=en_us,de_de 

configuring

<bean      class="org.springframework.beans.factory.config.propertyplaceholderconfigurer">     <property name="location">         <value>file:./config.properties</value>     </property> </bean> <bean     class="x.y.z.commandbean"     scope="prototype">     <property name="locales">         <bean class="org.springframework.util.stringutils" factory-method="tokenizetostringarray">             <constructor-arg type="java.lang.string" value="${my.app.locales}"/>             <constructor-arg type="java.lang.string" value=","/>         </bean>     </property> </bean> 

and need

import org.apache.commons.lang3.localeutils;  public void setlocales(string[] localestrings) {    list<locale> locales = new arraylist<locale>(localestrings.length);    (string localename: arrays.aslist(localestrings)) {       locales.add(localeutils.tolocale(localename));    }    this.locales = locales; } 

this bit gludgy though. alternative, define wrapper class conversion above, , wire bean. hook class bean.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -