Thread: [morph-developer] Changing Morph so it does NOT pick up on Locale
Brought to you by:
orangeherbert,
sgarlatm
From: Matt S. <mat...@sp...> - 2009-10-16 17:27:10
|
Hey Matt B, It sure has been a while! I hope you are doing well. Today I had a French user of our application unable to use the application because Morph was unable to convert the String "3.33" to a Double. The reason was that Morph was trying to perform the conversion using French as the locale instead of English. This happens because currently Transfers extending from BaseTransformer are too smart when it comes to determining the Locale to use for performing conversions. For calls when the Locale is not specified when calling convert or copy, instead of simply using Locale.getDefault(), Morph's trying to find the Locale from Spring. This leads to unexpected behavior because methods like Integer.parseInt work when Morph doesn't. This has actually come up several times for us at Spider, so I am going to change BaseTransformer.getLocale() as follows. Here is the old version protected Locale getLocale() { Locale locale = null; if (ClassUtils.isClassPresent(SPRING_LOCALE_CONTEXT_HOLDER_CLASS)) { try { Class contextHolderClass = Class.forName(SPRING_LOCALE_CONTEXT_HOLDER_CLASS); Method getLocaleMethod = contextHolderClass.getMethod("getLocale", (Class[]) null); locale = (Locale) getLocaleMethod.invoke(null, (Object[]) null); } catch (Exception e) { log.warn("Unable to retrieve locale from Spring", e); } } if (locale == null) { locale = Locale.getDefault(); } return locale; } New version: protected Locale getLocale() { return Locale.getDefault(); } Sound good? Thanks! Matt -- This message is intended only for the named recipient. If you are not the intended recipient, you are notified that disclosing, copying, distributing, or taking any action in reliance on the contents of this information is strictly prohibited. |
From: Matt B. <gud...@ya...> - 2009-10-16 18:12:12
|
I see what you're saying. You want to default to the Locale where the app is _running_, rather than the user's Locale. I agree that that makes sense. Thanks, Matt B --- On Fri, 10/16/09, Matt Sgarlata <mat...@sp...> wrote: > From: Matt Sgarlata <mat...@sp...> > Subject: [morph-developer] Changing Morph so it does NOT pick up on Locale > To: "For developers of Morph itself. NOT for questions." <mor...@li...> > Date: Friday, October 16, 2009, 11:57 AM > Hey Matt B, > > It sure has been a while! I hope you are doing well. > > Today I had a French user of our application unable to use > the > application because Morph was unable to convert the String > "3.33" to a Double. The reason was that Morph > was trying to perform the conversion using French as the > locale instead of English. This happens because currently > Transfers extending from BaseTransformer are too smart when > it comes to determining the Locale to use for performing > conversions. For calls when the Locale is not specified > when calling convert or copy, instead of simply using > Locale.getDefault(), Morph's trying to find the Locale > from Spring. This leads to unexpected behavior because > methods like Integer.parseInt work when Morph doesn't. > > > > This has actually come up several times for us at Spider, > so I am going to change BaseTransformer.getLocale() as > follows. Here is the old version > > protected Locale getLocale() { > Locale locale = null; > > > if > (ClassUtils.isClassPresent(SPRING_LOCALE_CONTEXT_HOLDER_CLASS)) > { > try { > Class contextHolderClass = > Class.forName(SPRING_LOCALE_CONTEXT_HOLDER_CLASS); > Method getLocaleMethod = > > > > contextHolderClass.getMethod("getLocale", > (Class[]) null); > locale = (Locale) > getLocaleMethod.invoke(null, (Object[]) null); > } > catch (Exception e) { > > > log.warn("Unable to > retrieve locale from Spring", e); > } > } > > if (locale == null) { > locale = Locale.getDefault(); > } > > return locale; > > > } > > New version: > > protected Locale getLocale() { > > return Locale.getDefault(); > > } > > > Sound good? Thanks! > > Matt > -- > This message is intended only for the named recipient. If > you are not the intended recipient, you are notified that > disclosing, copying, distributing, or taking any action in > reliance on the contents of this information is strictly > prohibited. > > > > > -----Inline Attachment Follows----- > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry(R) Developer Conference > in SF, CA > is the only developer event you need to attend this year. > Jumpstart your > developing skills, take BlackBerry mobile applications to > market and stay > ahead of the curve. Join us from November 9 - 12, 2009. > Register now! > http://p.sf.net/sfu/devconference > -----Inline Attachment Follows----- > > _______________________________________________ > morph-developer mailing list > mor...@li... > https://lists.sourceforge.net/lists/listinfo/morph-developer > |