Re: Struts2 : formatting and entering doubles consistently through the whole application not depending on locale

2012-06-20 Thread Pierre TEMPLIER
issue created : https://issues.apache.org/jira/browse/WW-3843

Pierre.

On Wed, Jun 20, 2012 at 3:32 PM, Łukasz Lenart
 wrote:
> 2012/6/20 Pierre TEMPLIER :
>> 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

2012-06-20 Thread Pierre TEMPLIER
reading the docs I discovered the possibility to override default
typeconverters (cf:
http://struts.apache.org/2.3.4/xwork-core/apidocs/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverter.html
)

== Quote from the docs
As from version 2.3.2 you can override default converters by
implementting TypeConverter interface and specifying beans in
struts.xml as follow: 

I tried with that approach by creating a new TypeConverter (roughly
copied from com.opensymphony.xwork2.conversion.impl.NumberConverter)
adding the following line in struts.xml right after the  tag


but the webapp failed to start with the following error.

Caused by: Bean type interface
com.opensymphony.xwork2.conversion.TypeConverter with the name number
has already been loaded by [unknown location] - bean -
file:/D:/dev/tomcat/webapps/blank/WEB-INF/classes/struts.xml:10:132
at 
com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:227)

Am I missing something ?

Pierre.

On Tue, Jun 19, 2012 at 9:18 PM, Dave Newton  wrote:
> On Tue, Jun 19, 2012 at 1:02 PM, Chris Pratt wrote:
>
>> If you want to handle parsing yourself, make your action properties take
>> "String" parameters and do the parsing in the action.
>>
>
> Probably better to do  your own type converter, though, particularly if
> it's app-wide.
>
> Dave

-
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

2012-06-19 Thread Pierre TEMPLIER
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  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 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

2012-06-19 Thread Pierre TEMPLIER
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:  = 
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  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 > 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

2012-06-18 Thread Pierre TEMPLIER
In a localized application with 2 languages : French and English.
I want users to be able to enter (HTML ) 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



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 ThreadLocal decimalFormat = new
ThreadLocal() {
  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