Adam Zimowski <zimowski74 <at> gmail.com> writes:

> 
> Is there a way to access message catalog of some page or component
> from another page or component? I know of two ways to do this, but
> both are "hacks" IMHO:
> 
> class SomePage {
> 
> @Inject
> private Messages _messages;
> 
> public getMessages() {
>  return _messages;
> }
> }
> 
> class Foo {
> 
> @InjectPage
> private SomePage _page;
> 
> // now I can access messages from _page
> }
> 
> Above way is a pain because every page/component needs to explicitly
> expose message catalog for use by other page. Another way to do this
> would be to obtain page/component resource path, and do it
> old-fashioned way with java.util.Property - ughh... !
> 
> What I was looking for is some support by Messages, perhaps overriden
> method get(String key):
> 
> Messages.get(String resourcePath, String key)
> Messages.get(Class component, String key)
> 
> The thing is, that I need to read another componen't message catalog
> not knowing ahead of time what the comopnent is. I don't see a "clean"
> way of doing it at the moment, any ideas?
> 
> -adam
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe <at> tapestry.apache.org
> For additional commands, e-mail: users-help <at> tapestry.apache.org
> 
> 


Hello Adam

One posibility is to Inject ComponentSource and ComponentMessageSource, after 
that you can use ComponentSource to get the page by name, and use 
ComponentMessageSource to get the page Messages, something like:

private ComponentMessagesSource _componentMessageSource;
        
private ComponentSource _componentSource;

...
Component page = _componentSource.getPage("foo");
Messages messages = _componentMessageSource.getMessages(
                            page.getComponentResources().getComponentModel(), 
page.getComponentResources().getLocale()); 
....


Maybe it would be more clean to create a specific service that you can inject 
to your page.

Hope this helps.
Bye



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

Reply via email to