You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Johan Compagner <jc...@j-com.nl> on 2000/12/09 11:59:19 UTC

i would like that MessageResources.getMessage(String) returns a string of the clients locale (not default)

Hi,

I want this because i don't have the a handle to the session object at all time so that i can
call the MessageResources.getMessage(Locale, String)  with the locale of the user.
(for example in a ActionForm class where i want client localised messages!!)

how do i those in the form bean? I know i could do it in a Action and set the properties
before it. But i want to generate the strings when the wanted property is called because
users can switchs locales all the time!!

See my previous mail for more info: getting Locale strings in a ActionForm

johan


Re: i would like that MessageResources.getMessage(String) returns a string of the clients locale (not default)

Posted by Johan Compagner <jc...@j-com.nl>.
> One challenge with using a static method here is that it would be global to the entire web
> applciation.  That's fine if all you care about is the *server* Locale, but the static method has
> no way to know what the client's Locale is without the session either.

Yes i had the idee to use a MessageResource object for every client (in which the locale is also auto set)
But then you have the same problem. how do i get that object, because it must also be stored in the session bean.


> > how do i those in the form bean? I know i could do it in a Action and set the properties
> > before it. But i want to generate the strings when the wanted property is called because
> > users can switchs locales all the time!!
> >
> > See my previous mail for more info: getting Locale strings in a ActionForm
> >
> 
> One thing that makes this much easier in the 1.0 code base is that your validate() method
> receives a reference to the request, so that you can go get request and session attributes.

That is to late. Because i want to use it to fill html options. I want to have 3 get methods for a select:
getType() for what is selected.
getTypeValues() what types there are.
getTypeLabels() what labels must be shown.

And the getTypeLabels() must be localised!


> 
> Additionally (and this works in 0.5 as well), if you are storing your ActionForm beans themselves
> in the session, you can implement HttpSessionBindingListener.  Then, when your bean is stored as
> a session attribute, the valueBound() method is called -- including a reference to the session
> itself.

a ActionForm is auto inserted into a session object i believe, so if i implement that listener i auto get a 
session object?! That's exactly what i wanted thx!

johan



Re: i would like that MessageResources.getMessage(String) returns a string of the clients locale (not default)

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Johan Compagner wrote:

> Hi,
>
> I want this because i don't have the a handle to the session object at all time so that i can
> call the MessageResources.getMessage(Locale, String)  with the locale of the user.
> (for example in a ActionForm class where i want client localised messages!!)
>

One challenge with using a static method here is that it would be global to the entire web
applciation.  That's fine if all you care about is the *server* Locale, but the static method has
no way to know what the client's Locale is without the session either.

>
> how do i those in the form bean? I know i could do it in a Action and set the properties
> before it. But i want to generate the strings when the wanted property is called because
> users can switchs locales all the time!!
>
> See my previous mail for more info: getting Locale strings in a ActionForm
>

One thing that makes this much easier in the 1.0 code base is that your validate() method
receives a reference to the request, so that you can go get request and session attributes.

Additionally (and this works in 0.5 as well), if you are storing your ActionForm beans themselves
in the session, you can implement HttpSessionBindingListener.  Then, when your bean is stored as
a session attribute, the valueBound() method is called -- including a reference to the session
itself.

>
> johan

Craig McClanahan