You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jonathan O'Connor <Jo...@xcom.de> on 2004/09/02 13:45:07 UTC

Getting localized properties of a component without the component [auf Viren geprueft]

Folks, I have come up with a snazzy (can't say "groovy" any more :-) way 
of turning Exceptions into nice localized formatted messages.

What I do is make a message key from the Exception class name, and then 
look this up in the current page's properties. However, I would like to 
have a default set of properties, which are kept with a component. 
However, the DefaultComponentMessagesSource insists on having an actual 
component to query.

In getLocalizedProperties(IComponent component) it calls 
component.getSpecification().getSpecificationLocation(), and 
component.getPage().getLocale().
After that the code only uses this IResourceLocation and Locale.

Would anyone mind if I extracted that code, and made it public.

Howard's earlier message on getting the page specification means I can 
easily get the specification location too.

        IEngine engine = cycle.getEngine();
        ISpecificationSource source = engine.getSpecificationSource();
        INamespace namespace = source.getApplicationNamespace();
        IComponentSpecification pageSpec = 
namespace.getPageSpecification("Foo");

Of course, any better solutions will be eagerly read.
Ciao,
Jonathan O'Connor
XCOM Dublin