You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Stephan Windmüller <st...@cs.tu-dortmund.de> on 2009/09/17 15:54:22 UTC

Using locale from user setting after login

Hello!

Our application allows the user to his preferred language permanently.
The value is stored in the user database and retrieved when the user
logs in.

But I am unsure about how to set the locale correctly after login.
Currently it is set with PersistentLocale.set in the layout component
which is used for every page, concretely in the SetupRender-method. This
does not work for the first page after login.

The localization guide[0] is very clear about this:

"You will see the new locale take effect on the next request. If it is
changed in a component event request (which is typical), the new locale
will be used in the subsequent page render request."

So is there a way to implement this setting?

TIA
 Stephan

[0] http://tapestry.apache.org/tapestry5/guide/localization.html

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


Re: Using locale from user setting after login

Posted by ccordenier <Ch...@atosorigin.com>.
Am I right if I say that Tapestry does not use a cookie anymore to persist
the locale ? And that the PersistentLocale does not persist the locale
accross a request ?

(Comparing to Tapestry 5.0.18)


Stephan Windmüller-8 wrote:
> 
> On Fri, 18. Sep 2009, Stephan Windmüller wrote:
> 
>> > Use a RequestFilter for setting the locale.
>> But I am unsure about how to implement this.
> 
> Okay, I asked for help a little too quickly. Some things I figured out
> myself, but still the filter does not work.
> 
>> Additionally I have to figure out if the user is logged in because
>> otherwise the database will return an error when I receive the saved
>> locale. The Request class does not have getRemoteUser().
> 
> Here I used RequestGlobals.
> 
>> And is it possible to use Beans in the RequestFilter which I would
>> Inject on normal pages?
> 
> That is possible using the build-Methods in AppModule itself.
> 
> So my code looks now like this:
> 
>   public RequestFilter buildLocaleFilter(final RequestGlobals globals,
> final PersistentLocale persistentLocale){
>     return new RequestFilter(){
>       public boolean service(Request request, Response response,
> RequestHandler handler) throws IOException {
>         if (globals.getHTTPServletRequest().getRemoteUser() != null) {
>           Locale preferredLanguage =
> getDatabaseUser().getPreferredLanguage();
> 	  persistentLocale.set(preferredLanguage);
>         }
>     	return handler.service(request, response);
>       }
>     };
>   }
> 
> According to the debug output the locale is set, but that did not change
> anything on the page.
> 
> - Stephan
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Using-locale-from-user-setting-after-login-tp25491734p25530316.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: Using locale from user setting after login

Posted by Stephan Windmüller <st...@cs.tu-dortmund.de>.
On Fri, 18. Sep 2009, Stephan Windmüller wrote:

> > Use a RequestFilter for setting the locale.
> But I am unsure about how to implement this.

Okay, I asked for help a little too quickly. Some things I figured out
myself, but still the filter does not work.

> Additionally I have to figure out if the user is logged in because
> otherwise the database will return an error when I receive the saved
> locale. The Request class does not have getRemoteUser().

Here I used RequestGlobals.

> And is it possible to use Beans in the RequestFilter which I would
> Inject on normal pages?

That is possible using the build-Methods in AppModule itself.

So my code looks now like this:

  public RequestFilter buildLocaleFilter(final RequestGlobals globals, final PersistentLocale persistentLocale){
    return new RequestFilter(){
      public boolean service(Request request, Response response, RequestHandler handler) throws IOException {
        if (globals.getHTTPServletRequest().getRemoteUser() != null) {
          Locale preferredLanguage = getDatabaseUser().getPreferredLanguage();
	  persistentLocale.set(preferredLanguage);
        }
    	return handler.service(request, response);
      }
    };
  }

According to the debug output the locale is set, but that did not change
anything on the page.

- Stephan

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


Re: Using locale from user setting after login

Posted by Stephan Windmüller <st...@cs.tu-dortmund.de>.
Thiago H. de Paula Figueiredo wrote:

>> We are using form based login from the application server (tomcat).
>> So we are unable to modify the login logic. :-/
> Use a RequestFilter for setting the locale.

Thanks, that looks like the correct place to put this code.

But I am unsure about how to implement this. Is there any documentation
of AppModule besides the JavaDoc or are there any examples for
implemented RequestFilters besides the simple TimingFilter?

Additionally I have to figure out if the user is logged in because
otherwise the database will return an error when I receive the saved
locale. The Request class does not have getRemoteUser().

And is it possible to use Beans in the RequestFilter which I would
Inject on normal pages?

Regards
 Stephan

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


Re: Using locale from user setting after login

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Thu, 17 Sep 2009 11:43:54 -0300, Stephan Windmüller  
<st...@cs.tu-dortmund.de> escreveu:

> We are using form based login from the application server (tomcat).
> So we are unable to modify the login logic. :-/

Use a RequestFilter for setting the locale.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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


Re: Using locale from user setting after login

Posted by Stephan Windmüller <st...@cs.tu-dortmund.de>.
Ulrich Stärk wrote:

>> But I am unsure about how to set the locale correctly after login.
>> Currently it is set with PersistentLocale.set in the layout component
>> which is used for every page, concretely in the SetupRender-method.
>> This does not work for the first page after login.
> Already set it in the login logic. The following redirect should then
> be in the new locale.

We are using form based login from the application server (tomcat).
So we are unable to modify the login logic. :-/

Regards
 Stephan Windmüller

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


Re: Using locale from user setting after login

Posted by Ulrich Stärk <ul...@spielviel.de>.
Already set it in the login logic. The following redirect should then be in the new locale.

Uli

On 17.09.2009 15:54 schrieb Stephan Windmüller:
> Hello!
> 
> Our application allows the user to his preferred language permanently.
> The value is stored in the user database and retrieved when the user
> logs in.
> 
> But I am unsure about how to set the locale correctly after login.
> Currently it is set with PersistentLocale.set in the layout component
> which is used for every page, concretely in the SetupRender-method. This
> does not work for the first page after login.
> 
> The localization guide[0] is very clear about this:
> 
> "You will see the new locale take effect on the next request. If it is
> changed in a component event request (which is typical), the new locale
> will be used in the subsequent page render request."
> 
> So is there a way to implement this setting?
> 
> TIA
>  Stephan
> 
> [0] http://tapestry.apache.org/tapestry5/guide/localization.html
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 

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