I've implemented something like this using Struts 2.0.12, although it
was quite a bit of work to get running.

I implemented a database-backed TextProvider (DatabaseTextProvider)
which reads resources from the database instead of from resource
bundles. It caches the text so as not to load the database too heavily.
In the getText() methods I use ActionContext.getContext().getSession()
to get the current session, then use session attributes to figure out
which text to display for the current user. Our application is used by
several different companies so we need to customise the text based on
which company the user is logged into.

I then created an extension of ActionSupport which overrides all the
getText() methods, delegating to DatabaseTextProvider which is injected
using Spring. This means that text supplied by DatabaseTextProvider is
available in actions and JSPs, and will be used by any struts tags.

This worked OK but Struts does not make it easy to override TextProvider
in the validation interceptor. To get this working I had to extend
DelegatingValidatorContext, AnnotationActionValidatorManager and use
them in a custom AnnotationValidationInterceptor and configure the
interceptor stack to use this instead of the default validation
interceptor. A bit of a kludge (and some copy-and-pasted code) but it
works OK. If you don't need to customise validation text then you won't
need to do this.
 
Hope this helps.

Peter

-----Original Message-----
From: Ramez Hassan [mailto:[EMAIL PROTECTED] 
Sent: 17 November 2008 10:02
To: 'Struts Users Mailing List'
Subject: RE: Resource Bundle per session

Thanx for the prompt Nuwan. However, this will cause overlapping in
users
different resource bundles. As LocalizedTextUtils store the default
bundle
list in a static map in static member variable.

-----Original Message-----
From: Nuwan Chandrasoma [mailto:[EMAIL PROTECTED] 
Sent: Sunday, November 16, 2008 5:32 PM
To: Struts Users Mailing List
Subject: Re: Resource Bundle per session

http://struts.apache.org/2.x/docs/how-do-i-set-a-global-resource-bundle.
html

<http://struts.apache.org/2.x/docs/how-do-i-set-a-global-resource-bundle
.htm
l>

Instead of this ServletContextListener  you can  have a 
 HttpSessionListener, just a suggestion, i haven't tried it.

Thanks,
Nuwan C.

Ramez Hassan wrote:
> Dear All,
>
>  
>
> Are there any configuration or mechanism for struts 2 to load resource
> bundle for localized messages per user session?
>
> In other words I need to display localized messages for users based on
their
> profile and role, but struts 2 loads messages either by request which
is
for
> development and not recommended for production.
>
>  
>
> Regards,
>
> Ramez Hassan
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


_______________________________________________________________________
The information contained in this e-mail is confidential and may be privileged. 
It is intended for the addressee only. If you are not the intended recipient, 
please delete this e-mail immediately. The contents of this e-mail must not be 
disclosed or copied without the sender's consent. The statements and opinions 
expressed in this message are those of the author and do not necessarily 
reflect those of the company. The company does not take any responsibility for 
the views of the author.

Registered Office: IT-Freedom Limited, 9 Minster Court, Tuscam Way, Camberley, 
Surrey GU15 3YY 
Registered in England, Number: 04500346
_______________________________________________________________________

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to