You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Bernd Hofner <be...@gmx.net> on 2005/04/03 14:04:35 UTC

Locale-specific ActionForm population

Is there a way to persuade Struts to use the default Locale to populate 
  ActionForms?

Tracing the code I saw the the RequestProcessors processPopulate() 
method ends up using the setProperty() methods of the BeanUtil class.
This one is not using the Xy-Format classes to parse HTTP form entries, 
but instead just uses non-locale aware conversion functions (like 
Double.valueOf(string ...).

This is quite annoing as my (German) users certainly will expect to 
enter their numbers using a "," as a decimal point.

The commons-beanutil.jar conains another set of utility classes that 
seem to be locale aware (starting from the entry point class 
LocaleBeanUtil).

How do I get Struts to uses these classes?

I tried a custom RequestProcessor with an overloaded processPopulate() 
method that replaces the call to BeanUtil.populate(...) with 
LocaleBeanUtil.populate() but I had the feeling that the thread-local 
singleton construction mechanismn created a BeanUtilsBean instance 
instead of a LocaleBeanUtilsBean.
However, the ActionForm is still not populated in the desired way...
Needless to say that I checked that both the Locale.getDefaultLocale() 
and the LocalBeanUtil.getDefaultLocale() are actually set to DE-de.

What am I doing wrong? I suspect that I'm actually thinking to 
complicated. I guess the Struts framework has a little switch somewhere 
to tell it wich kind of locale to use for form poplulation...

Thanks for yours help!

Amarookie


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Locale-specific ActionForm population

Posted by Bernd Hofner <be...@gmx.net>.
Hello Hubert,

thanks for your reply, I'll have a look at your link.

 >possible solutions to your problem using the approach you're following

Is there another approach?
Do people specify there ActionForm fields as string and do the locale
specific parsing when copying the ActionForm fields to their model bean?
(And vice versa?)
This seems to be a lot of manual copy-one-attribute-to-another-attribute 
coding. I expected a framework to take away such "senseless" coding away 
from me...
I like to use copies of model beans as form members, using these beans 
to populate my HTTP form fields (using velocity).
Is this some kind of "unstruttish" approach?


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Locale-specific ActionForm population

Posted by Hubert Rabago <hr...@gmail.com>.
I don't have time right now to investigate the possible solutions to
your problem using the approach you're following.  I just wanted to
point out that FormDef might be able to help you out depending on how
you're using your action form.

http://www.rabago.net/struts/formdef/manual.htm#specifyingformats

Using FormDef, you can specify localized formats for dates and
numbers.  There is a sample application (locale.war) that illustrates
this feature.

Hubert

On Apr 3, 2005 7:04 AM, Bernd Hofner <be...@gmx.net> wrote:
> Is there a way to persuade Struts to use the default Locale to populate
>  ActionForms?
> 
> Tracing the code I saw the the RequestProcessors processPopulate()
> method ends up using the setProperty() methods of the BeanUtil class.
> This one is not using the Xy-Format classes to parse HTTP form entries,
> but instead just uses non-locale aware conversion functions (like
> Double.valueOf(string ...).
> 
> This is quite annoing as my (German) users certainly will expect to
> enter their numbers using a "," as a decimal point.
> 
> The commons-beanutil.jar conains another set of utility classes that
> seem to be locale aware (starting from the entry point class
> LocaleBeanUtil).
> 
> How do I get Struts to uses these classes?
> 
> I tried a custom RequestProcessor with an overloaded processPopulate()
> method that replaces the call to BeanUtil.populate(...) with
> LocaleBeanUtil.populate() but I had the feeling that the thread-local
> singleton construction mechanismn created a BeanUtilsBean instance
> instead of a LocaleBeanUtilsBean.
> However, the ActionForm is still not populated in the desired way...
> Needless to say that I checked that both the Locale.getDefaultLocale()
> and the LocalBeanUtil.getDefaultLocale() are actually set to DE-de.
> 
> What am I doing wrong? I suspect that I'm actually thinking to
> complicated. I guess the Struts framework has a little switch somewhere
> to tell it wich kind of locale to use for form poplulation...
> 
> Thanks for yours help!
> 
> Amarookie
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org