You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Sebastiaan van Erk <se...@sebster.com> on 2006/02/11 11:58:36 UTC

Forcing default locale

Hi,

How can you set the locale of a page on the *first* page load of the 
entire application. I store the locale in a cookie, and when the user 
comes to the login page I want it to display in their favorite locale.

I searched the list and learned that you can change the locale in a 
listener by:

	cycle.cleanup();
	throw new PageRedirectException(this);

However, this does NOT work in the pageBeginRender method... Maybe it's 
already too late to try to change the locale there, but I don't know 
where to change it otherwise. Does anybody know how to do it before the 
first page of the application is displayed?

Thanks in advance!

Greetings,
Sebastiaan

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


Re: Forcing default locale

Posted by Sebastiaan van Erk <se...@sebster.com>.
Hi,

After searching and reading the tapestry source I finally found a 
working solution (the Tapestry 4 way) of setting the default locale.

The behavior I want is that if no locale cookie is set, the default 
locale specified in a meta key in my .application file is used. I want 
this behavior since the target audience is Dutch, and I don't want Dutch 
users using an English browser to get the English site by default. 
However I do want to allow people to be able to change the language to 
English on request.

The trick was to clone the 
org.apache.tapestry.services.impl.RequestLocaleManager class and fix it 
so it would not look at the browser supplied locale at all. 
Unfortunately I was not able to override this class since it users 
private properties for which there are no setters.

After cloning and adjusting this class I overrode the 
tapestry.request.RequestLocaleManager service point with my own 
implementation as described by 
http://jakarta.apache.org/hivemind/override.html.

Greetings,
Sebastiaan

Mul wrote:
> After you set the locale, ensure that cycle.cleanUpRequest (I dont quite
> remember the method name), is called and then re-activate the page you want
> to get the locale refreshed.
> 
> 
> On 2/12/06, Sebastiaan van Erk <se...@sebster.com> wrote:
>> Hi,
>>
>> After some more reading I found out that Tapestry already saves the user
>> locale in a cookie, so that's good and it only comes down to setting the
>> default locale. In the Wiki I found the following page:
>>
>> http://wiki.apache.org/jakarta-tapestry/DefaultLocale
>>
>> which says to override the base engine to do:
>>
>> public final void setLocale(Locale locale)
>>    {
>>       if (getLocale() == null)
>>          super.setLocale(new Locale(defaultLanguage, defaultCountry));
>>       else
>>          super.setLocale(locale);
>>    }
>>
>> First of all this doesn't seem like "the Tapestry 4" way of doing
>> things, but secondly, I tried this and it did not work. I display the
>> engine locale on my pages and it clearly shows that it *is* the default
>> locale, but the pages are still displayed in the request's locale (which
>> in this case happened to be a different but accepted locale).
>>
>> What is the correct way to set the default locale? Should I register my
>> own RequestLocaleManager on the RequestLocaleManager service point?
>>
>> Thanks in advance,
>> Sebastiaan
>>
>> Sebastiaan van Erk wrote:
>>> Hi,
>>>
>>> How can you set the locale of a page on the *first* page load of the
>>> entire application. I store the locale in a cookie, and when the user
>>> comes to the login page I want it to display in their favorite locale.
>>>
>>> I searched the list and learned that you can change the locale in a
>>> listener by:
>>>
>>>     cycle.cleanup();
>>>     throw new PageRedirectException(this);
>>>
>>> However, this does NOT work in the pageBeginRender method... Maybe it's
>>> already too late to try to change the locale there, but I don't know
>>> where to change it otherwise. Does anybody know how to do it before the
>>> first page of the application is displayed?
>>>
>>> Thanks in advance!
>>>
>>> Greetings,
>>> Sebastiaan
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>>
> 

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


Re: Forcing default locale

Posted by Mul <ms...@gmail.com>.
After you set the locale, ensure that cycle.cleanUpRequest (I dont quite
remember the method name), is called and then re-activate the page you want
to get the locale refreshed.


On 2/12/06, Sebastiaan van Erk <se...@sebster.com> wrote:
>
> Hi,
>
> After some more reading I found out that Tapestry already saves the user
> locale in a cookie, so that's good and it only comes down to setting the
> default locale. In the Wiki I found the following page:
>
> http://wiki.apache.org/jakarta-tapestry/DefaultLocale
>
> which says to override the base engine to do:
>
> public final void setLocale(Locale locale)
>    {
>       if (getLocale() == null)
>          super.setLocale(new Locale(defaultLanguage, defaultCountry));
>       else
>          super.setLocale(locale);
>    }
>
> First of all this doesn't seem like "the Tapestry 4" way of doing
> things, but secondly, I tried this and it did not work. I display the
> engine locale on my pages and it clearly shows that it *is* the default
> locale, but the pages are still displayed in the request's locale (which
> in this case happened to be a different but accepted locale).
>
> What is the correct way to set the default locale? Should I register my
> own RequestLocaleManager on the RequestLocaleManager service point?
>
> Thanks in advance,
> Sebastiaan
>
> Sebastiaan van Erk wrote:
> > Hi,
> >
> > How can you set the locale of a page on the *first* page load of the
> > entire application. I store the locale in a cookie, and when the user
> > comes to the login page I want it to display in their favorite locale.
> >
> > I searched the list and learned that you can change the locale in a
> > listener by:
> >
> >     cycle.cleanup();
> >     throw new PageRedirectException(this);
> >
> > However, this does NOT work in the pageBeginRender method... Maybe it's
> > already too late to try to change the locale there, but I don't know
> > where to change it otherwise. Does anybody know how to do it before the
> > first page of the application is displayed?
> >
> > Thanks in advance!
> >
> > Greetings,
> > Sebastiaan
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

Re: Forcing default locale

Posted by Sebastiaan van Erk <se...@sebster.com>.
Hi,

After some more reading I found out that Tapestry already saves the user 
locale in a cookie, so that's good and it only comes down to setting the 
default locale. In the Wiki I found the following page:

http://wiki.apache.org/jakarta-tapestry/DefaultLocale

which says to override the base engine to do:

public final void setLocale(Locale locale)
   {
      if (getLocale() == null)
         super.setLocale(new Locale(defaultLanguage, defaultCountry));
      else
         super.setLocale(locale);
   }

First of all this doesn't seem like "the Tapestry 4" way of doing 
things, but secondly, I tried this and it did not work. I display the 
engine locale on my pages and it clearly shows that it *is* the default 
locale, but the pages are still displayed in the request's locale (which 
in this case happened to be a different but accepted locale).

What is the correct way to set the default locale? Should I register my 
own RequestLocaleManager on the RequestLocaleManager service point?

Thanks in advance,
Sebastiaan

Sebastiaan van Erk wrote:
> Hi,
> 
> How can you set the locale of a page on the *first* page load of the 
> entire application. I store the locale in a cookie, and when the user 
> comes to the login page I want it to display in their favorite locale.
> 
> I searched the list and learned that you can change the locale in a 
> listener by:
> 
>     cycle.cleanup();
>     throw new PageRedirectException(this);
> 
> However, this does NOT work in the pageBeginRender method... Maybe it's 
> already too late to try to change the locale there, but I don't know 
> where to change it otherwise. Does anybody know how to do it before the 
> first page of the application is displayed?
> 
> Thanks in advance!
> 
> Greetings,
> Sebastiaan
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 

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