Re: Struts2 : formatting and entering doubles consistently through the whole application not depending on locale
issue created : https://issues.apache.org/jira/browse/WW-3843 Pierre. On Wed, Jun 20, 2012 at 3:32 PM, Łukasz Lenart lukasz.len...@googlemail.com wrote: 2012/6/20 Pierre TEMPLIER pierre.templ...@gmail.com: Am I missing something ? Nothing, my mistake :/ I forgot to define aliases, please raise an issue Thanks regards -- Łukasz mobile +48 606 323 122 http://www.lenart.org.pl/ Warszawa JUG conference - Confitura http://confitura.pl/ - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Struts2 : formatting and entering doubles consistently through the whole application not depending on locale
that's it, the parser expects localized input. I'd like to be able to handle parsing by myself for Doubles (without depending on the locale). I was able to register an application-wide DoubleConverter with primitive type double this way : == xwork-conversion.properties == # syntax: type = converterClassName double = com.company.app.DoubleConverter it works but it looks more like a hack than something i can rely on as it based on the bug Łukasz indicated (https://issues.apache.org/jira/browse/WW-3171). I might be surprised to see this no more working when this bug is fixed. Pierre. On Mon, Jun 18, 2012 at 5:28 PM, Chris Pratt thechrispr...@gmail.com wrote: I think the problem is that the French locale specifies that it should be written as 445.000,00 not 445,000.00. The parser expects localized input. (*Chris*) On Mon, Jun 18, 2012 at 7:06 AM, Łukasz Lenart lukasz.len...@googlemail.com wrote: I think the problem is related to primitive converter which doesn't include Locale in conversion, take a look on that bug and related https://issues.apache.org/jira/browse/WW-3171 Regards -- Łukasz mobile +48 606 323 122 http://www.lenart.org.pl/ Warszawa JUG conference - Confitura http://confitura.pl/ - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Struts2 : formatting and entering doubles consistently through the whole application not depending on locale
Locale.FRENCH and Locale FRANCE should output something like 345 987,246 i can confirm that with a slightly modified struts-blank app (defaultStack and a textfield mapped to a Double) i'm having a conversion error for Doubles too. It doesn't like the thousand separator (space) and it converts coma to point ( ',' to '.' ) Pierre. On Tue, Jun 19, 2012 at 9:33 AM, J. Garcia jogaco...@gmail.com wrote: According to the Java formatting api, the French locale for integers would look something like this: 345 987,246 http://docs.oracle.com/javase/tutorial/i18n/format/numberFormat.html As I have been working on integer l10n, I have tested this, and if I set French locale and enter an integer like this: 345 987, I get a conversion error. J. On Mon, Jun 18, 2012 at 5:28 PM, Chris Pratt thechrispr...@gmail.comwrote: I think the problem is that the French locale specifies that it should be written as 445.000,00 not 445,000.00. The parser expects localized input. (*Chris*) On Mon, Jun 18, 2012 at 7:06 AM, Łukasz Lenart lukasz.len...@googlemail.com wrote: I think the problem is related to primitive converter which doesn't include Locale in conversion, take a look on that bug and related https://issues.apache.org/jira/browse/WW-3171 Regards -- Łukasz mobile +48 606 323 122 http://www.lenart.org.pl/ Warszawa JUG conference - Confitura http://confitura.pl/ - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Struts2 : formatting and entering doubles consistently through the whole application not depending on locale
In a localized application with 2 languages : French and English. I want users to be able to enter (HTML input) doubles formatted the same way wether they are using english or french locale. i.e : - english_user enter 445,000.00 for orderItem.price and this data is correctly parsed to 445000.0d and put into the corresponding bean property - french_user enter 445,000.00 for orderItem.price and this is also correctly parsed to 445000.0d and put into the corresponding bean property i'm using struts2 2.3.4 with defaultStack and jdk 1.5.0_22 i'm using s:textfield like suggested in the docs : http://struts.apache.org/2.3.4/docs/formatting-dates-and-numbers.html s:textfield name=orderItem.price value=%{getText('format.number',{orderItem.price})} / with english locale it's ok, with french locale it's not. when submitting the form with french locale i have errors : Invalid field value for field xxx and in the logs i get : [WARN ] com.opensymphony.xwork2.ognl.OgnlValueStack - Error setting expression 'orderItem.price' with value '[Ljava.lang.String;@c98901' (struts is trying to use a setter with a String parameter whereas it should find the one with a Double parameter) I've also tried using a Converter with no success (see code at the end) Is there any (simple) way to achieve what i've explained here ? Regards, Pierre. == Converter Code == public class DoubleConverter extends StrutsTypeConverter { private static ThreadLocalDecimalFormat decimalFormat = new ThreadLocalDecimalFormat() { protected DecimalFormat initialValue() { final DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(Locale.US); df.applyPattern(#,##0.00); return df; }; }; public Object convertFromString(Map context, String[] values, Class toClass) { String myString = values[0]; if (myString == null || .equals(myString)) { return 0d; } try { return decimalFormat.get().parse(myString); } catch (ParseException e) { throw new TypeConversionException(e); } } public String convertToString(Map context, Object o) { if (o == null) { return 0.00; } return decimalFormat.get().format(((Double) o).doubleValue()); } } - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org