On 2011-06-30 16:13, diogoeag wrote:
I'm using tapestry 5.2.5 and trying to override the a service to get
database based localization. I've searched in the forum and the solutions
present here don't work.
Did you try "T5 : Expanding Messages Catalog for localization from
arbitrary source" (http://markmail.org/thread/frvx2mbmq34wg4xu) - I
think this should still work.
What service should I override? ComponentMessagesSource.class or
Messages.class?
I've tried to do as in the manual:
@Contribute(ServiceOverride.class)
public static void
setupApplicationServiceOverrides(MappedConfiguration<Class,Object>
configuration)
{
configuration.addInstance(ComponentMessagesSource.class,
DatabaseSource.class);
}
But I get an error saying:
Caused by: java.lang.IllegalArgumentException: Service 'ServiceOverride' is
configured using org.apache.tapestry5.ioc.OrderedConfiguration, not
org.apache.tapestry5.ioc.MappedConfiguration.
Just tried that with a dummy implementation (returning "hello" for all
messages) of DatabaseSource and it worked (based on 5.2.5 quickstart).
Don't know how you get this exception!?
Anyone got something like this implemented and working? Is there any other
way to do this?
Another way is not to override a service but contribute to it - in this
case to ComponentMessagesSource. In your module class you add the
contribution:
public static void contributeComponentMessagesSource(
OrderedConfiguration<Resource> configuration)
{
configuration.add("DatabaseCatalog", DatabaseResource.class);
}
The problem here ist that you have to implement Resource which is made
for file systems and not for databases but I guess it should work
anyway. Just return some arbitary value like "db" in 'getFile' method -
Tapestry will call 'forFile' with any locale combination relevant for
rendering in - in this case "db_en_US", "db_en" and "db". Return the
database values in properties format when 'openStream' is called.
Hope that works - when I think about it maybe it's better to override or
decorate the service.
--
Chris
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org