-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: Internationalized data in Hibernate
PostPosted: Wed Nov 24, 2004 3:17 am 
Newbie

Joined: Wed Nov 24, 2004 2:44 am
Posts: 11
Yesterday I discovered this thread http://blog.hibernate.org/cgi-bin/blosxom.cgi/2004/06/23#i18n. Gavin King discusses his preferred solution to the problem of using internationalized reference data as UI labels.

Unfortunately I don't understand how to implement the User.current().getLanguage() stuff. So is anybody out there able to send me a complete example of the source code of the LabelUserType and User objects ?

Thanks in advance for your help,

Bertrand GILLIS
bgillis@mainsys.be


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 24, 2004 3:55 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Thats just an example "User" class with a static method. Any way you can get the "language setting of the currently logged in user" is fine.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 24, 2004 4:43 am 
Newbie

Joined: Wed Nov 24, 2004 2:44 am
Posts: 11
OK. That's what I've guessed.

So in Gavin's example, how can I grab "the language setting of the currently logged in user" in the LabelUserType object when categories are retrieved from the database ?

When I retrieve categories, I don't figure out how is it possible to specify "the language setting of the currently logged user" that must be used in the LabelUserType object. LabelUserType object is referenced only in mapping files.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 24, 2004 4:45 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Well, you have to write that User class yourself or use something similar provided by your security/authorization framework. Really, thats not important for the pattern, you just need that value at this point. How it gets there is a) trivial and b) not related to persistence.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 24, 2004 5:31 am 
Newbie

Joined: Wed Nov 24, 2004 2:44 am
Posts: 11
Sorry for my ignorance but it is not so trivial for me...

In my application, a User instance is stored in every new HttpSession when the user is correctly authentified. And I'm also able to retrieve the user's favorite language (locale) from this User instance. So I know how to get "the language setting of the currently logged in user". However I haven't got a clue how to get this User instance from within the LabelUserType class.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 24, 2004 5:55 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
well ... there are a lot of ways how to do that ... all are more or less not really beautifull ;-)

One possibility is to store the current User in a ThreadLocal ... then you can
- add a static "getCurrent()"-Method to the User-Object
- or get the currentUser directly from the ThreadLocal ...

I like this versions because you don't have a dependency to the HTTPSession ... i would use the static getCurrent() ...

as an example you can look in the "HibernateUtil"-Class where you can access the current HibernateSession via ThreadLocal ...

Hope it helps ...

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 24, 2004 6:17 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
There is a quick & dirty UserSession in CaveatEmptor as well.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 24, 2004 6:20 am 
Newbie

Joined: Wed Nov 24, 2004 2:44 am
Posts: 11
Thanks to you both for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 24, 2004 6:51 am 
Newbie

Joined: Wed Nov 24, 2004 2:44 am
Posts: 11
curio wrote:
well ... there are a lot of ways how to do that ... all are more or less not really beautifull ;-)
...
I like this versions because you don't have a dependency to the HTTPSession ... i would use the static getCurrent() ...
...


Just curious... what are the possible ways if I still want to store User instance in the HttpSession ? I'm using the ActionFilter of appFuse in my application to do that (http://raibledesigns.com/downloads/appfuse/api/org/appfuse/webapp/filter/ActionFilter.java.html)[/url]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 24, 2004 6:56 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
you can/should still add the User to your HttpSession ... with "no dependency" i've ment that the caller of "User.getCurrent()" doesn't need to know anything about a HttpSession ... even the implementation of "getCurrent()" needn't .. therefore it would still work if you want to use e.g. a Swing-GUI.

The only one knowing that the current User is in the HttpSession is the one setting the User to the ThreadLocal ...

Sorry for not making my point clearer ...

gtx
curio


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.