DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=11852>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=11852 The bean:message tag should accept Objects as arguments ------- Additional Comments From [EMAIL PROTECTED] 2002-09-08 14:23 ------- This is a bit long and I'm not very good explaining things in english, so excuse me. This is what I tested: ApplicationResources.properties snip ---------------------------------------------- date.test= Data actual: {0,date,long} ---------------------------------------------- test.jsp snip ----------------------------------------------- <bean:message key="date.test" arg0="<%=new java.util.Date()%>" /> ----------------------------------------------- And I get: ---------------------------------------------- Data actual: 7 / setembre / 2002 --------------------------------------------- (Note that my system locale is "ca", Catalan) Then I added an ApplicationResources_en.properties with the line: ---------------------------------------------- date.test= Current date: {0,date,long} ---------------------------------------------- I configured my browser to send "en" language, and I got: ---------------------------------------------- Current date: 7 / setembre / 2002 ---------------------------------------------- While I was expecting: ---------------------------------------------- Current date: September 7, 2002 ---------------------------------------------- I realized that the java.text.MessageFormat constructed in MessageResources.getMessage (line 327) was not using the user locale. MessageFormat uses DateFormat and NumberFormat when it has to process thing like {0,date,long} or {1,number,currency}. Both DateFormat and NumberFormat implement a static getInstance(Locale), and a static getInstance() that uses the system locale. For MessageFormat to call getInstance(Locale) when it needs a DateFormat or NumberFormat I changed MessageResources: --------------------------------------------------------------- diff -u -u -r1.14 MessageResources.java --- MessageResources.java 30 Jun 2002 03:38:30 -0000 1.14 +++ MessageResources.java 8 Sep 2002 13:46:12 -0000 @@ -324,7 +324,9 @@ else return ("???" + formatKey + "???"); } - format = new MessageFormat(escape(formatString)); + format = new MessageFormat(""); + format.setLocale(locale); + format.applyPattern(escape(formatString)); formats.put(formatKey, format); } -------------------------------------------------------- (From j2sdk javadoc I noted that after calling setLocale it's necessary to call applyPattern so It's no necessary to use the pattern in the constructor) With that applied ( and the previous patch for MessageTag to use Objects as args) my test works as expected. But I came across a weird effect: If I configured my browser to send "es" (Spanish), as I had no ApplicationResources_es, PropertyMessageResources used the default ApplicationResources, which is in Catalan (ca), but MessageResources is not aware that PropertyMessageResources had to fall to the default locale, and it used the user locale (es) to build the MessageFormat. So I end up with the message in Catalan (from de default ApplicationResources) and the Date formatted in Spanish! ------------------------------------------- Data actual: 8 de septiembre de 2002 ------------------------------------------- What do you think about it? I'm used to develop webapps that support several locales ("ca", "es", "en", "de" ...), and struts has helped us a lot, so I'm interested in this. IMHO MessageResources should have an abstract Locale[] getAvaliableLocales() or abstract Enumeration getAvaliableLocales() And processLocale in RequestProcessor should choose the locale from the avaliable locales in the application MessageResources, also it should use request.getLocales instead of request.getLocale (If my browser uses "ca" and "es" and the application has "en" (as default) and "es", struts will end up using "en" while the correct would be "es") I can code it I you think is worth it -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>