You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Lesaint Sébastien <le...@ginlex.com> on 2005/03/14 12:14:53 UTC

class TagUtils, retrieving a message bundle, code modification re quest

I originally wanted to send the message below to the dev-list, ended up on
the user-list, so I'm posting a copy to the list it belongs to.

Seb'

-----Message d'origine-----
De : Lesaint Sébastien 
Envoyé : lundi 14 mars 2005 10:43
À : Struts Users Mailing List
Objet : class TagUtils, retrieving a message bundle, code modification re
quest

Hello,

I've been looking into the source code (of both 1.2.4 and 1.2.6, not cvs),
and I have a question about the way a message bundle is looked up based on
its name.

I understand from the code that the resource bundle is search:
 - in the page context
 - if not found, in the request context
 - if not found, in the application context

This process make perfectly sense for me but I'm surprised how the search in
the application context is done. From the code, we can see that the bundle
is first searched by its name + the module prefix, then by its raw name.

I would have done it the other way around, for two reasons:
 - If I specify in the code the correct bundle name with the module prefix
appended, there is an extra search done (the one for "name + module prefix +
module prefix")
 - If I have two resources bundles, one in the default module, one in a
module "foo", with the same name in the config file, let's say for pictures
(so it would be called "ImagesResources"). If I am in the module foo, I
can't get access to the bundle "ImageResources" of the default module
because it will always find the bundle "ImagesResources/foo" first.


Before proposing reporting anything in bugzilla, I would like to know the
opinion of the community on this issue (assuming that I managed to make it
clear): should the lookup in application context be done first by raw name
or by "name + module prefix"?

Seb'

Re: class TagUtils, retrieving a message bundle, code modification re quest

Posted by Martin Cooper <mf...@gmail.com>.
I think the problem here is that you are trying to use modules and
bundles in a way that they were not designed to be used.

Modules, the way they are today, are intended to help split a Struts
application into multiple *independent* pieces. In your code, you
should never need to examine module prefixes, and you should be
accessing your resources using only the bundle names. Struts takes
care of ensuring that the correct bundles are in place, so that you
don't need to.

You seem to be trying to access one module's resources from a
different module. That's not something that the current module design
is set up for.

--
Martin Cooper


On Mon, 14 Mar 2005 12:14:53 +0100, Lesaint Sébastien
<le...@ginlex.com> wrote:
> 
> I originally wanted to send the message below to the dev-list, ended up on
> the user-list, so I'm posting a copy to the list it belongs to.
> 
> Seb'
> 
> -----Message d'origine-----
> De : Lesaint Sébastien
> Envoyé : lundi 14 mars 2005 10:43
> À : Struts Users Mailing List
> Objet : class TagUtils, retrieving a message bundle, code modification re
> quest
> 
> Hello,
> 
> I've been looking into the source code (of both 1.2.4 and 1.2.6, not cvs),
> and I have a question about the way a message bundle is looked up based on
> its name.
> 
> I understand from the code that the resource bundle is search:
>  - in the page context
>  - if not found, in the request context
>  - if not found, in the application context
> 
> This process make perfectly sense for me but I'm surprised how the search in
> the application context is done. From the code, we can see that the bundle
> is first searched by its name + the module prefix, then by its raw name.
> 
> I would have done it the other way around, for two reasons:
>  - If I specify in the code the correct bundle name with the module prefix
> appended, there is an extra search done (the one for "name + module prefix +
> module prefix")
>  - If I have two resources bundles, one in the default module, one in a
> module "foo", with the same name in the config file, let's say for pictures
> (so it would be called "ImagesResources"). If I am in the module foo, I
> can't get access to the bundle "ImageResources" of the default module
> because it will always find the bundle "ImagesResources/foo" first.
> 
> Before proposing reporting anything in bugzilla, I would like to know the
> opinion of the community on this issue (assuming that I managed to make it
> clear): should the lookup in application context be done first by raw name
> or by "name + module prefix"?
> 
> Seb'
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org