Hi, 

Thanks for your help, no it doesn’t seem to work.  I found a solution using 
decorate method, but I am not sure it’s really clean. 
public static ComponentMessagesSource 
decorateComponentMessagesSource(ComponentMessagesSource current, @Autobuild 
CustomComponentMessagesSourceImpl custom, UpdateListenerHub updateListenerHub)
{
    updateListenerHub.addUpdateListener(custom);
    return custom;
}
Just wondering if there is no cleaner way. 
I believe message formatter should be a service that should be overridable. 

My implementation works as follow if it detects in the format a MessageFormat 
pattern it will use a customer formatter, otherwise it will use the default 
MessageFormatterImpl.

Inside MapMessages:

private MessageFormatter buildMessageFormatter(String key)
{
    String format = get(key);
    if (MESSAGE_FORMAT_PATTERN.matcher(format).find()) {
        return new CustomMessageFormatterImpl(format, locale);
    }
    return new MessageFormatterImpl(format, locale);
}


> Le 17 juin 2021 à 12:41, Volker Lamp <volker.l...@gmail.com> a écrit :
> 
> Hello Numa,
> 
> I think you are missing withId() in your binder method to assign a unique
> name.
> 
> See https://tapestry.apache.org/ioc-cookbook-overriding-ioc-services.html 
> <https://tapestry.apache.org/ioc-cookbook-overriding-ioc-services.html>
> 
> Cheers,
> 
> Volker
> 
> 
> Am Do., 17. Juni 2021 um 12:20 Uhr schrieb Numa Schmeder <n...@dfacto.ch 
> <mailto:n...@dfacto.ch>>:
> 
>> Hello,
>> 
>> I am trying to override the ComponentMessageSource service with a custom
>> ComponentMessageSourceImpl. The main reason to override the service is to
>> be able to use a custom implementation of MapMessages in
>> MessageFormatterImpl.
>> Currently it uses only String Formatter, which is very good for some time
>> of formatting but less practical for i18n formatting as it doesn’t handle
>> plurals at all. I would like to revert to classic MessageFormat.
>> 
>> This is what I have done in my module:
>> @Contribute(ServiceOverride.class)
>> public static void
>> setupApplicationServiceOverrides(MappedConfiguration<Class<?>,Object>
>> configuration, @Local ComponentMessagesSource messagesSource)
>> {
>>    //  configuration.add(HibernateSessionSource.class,
>> hibernateSessionSource);
>>    //overriding existing default component message source to add
>> MessageFormat
>>    configuration.override(ComponentMessagesSource.class, messagesSource);
>> 
>> }
>> 
>> public static ComponentMessagesSource
>> buildCustomComponentMessagesSource(UpdateListenerHub updateListenerHub,
>> @Autobuild ComponentMessagesSourceImpl service)
>> {
>>    updateListenerHub.addUpdateListener(service);
>>    return service;
>> }
>> 
>> If anyone has a clue on how to override this service this would be very
>> helpful. I always end up with 2 conflicting service, and
>> configuration.override doesn’t work.
>> It tapestry module ComponentMessageSource is built using a builder method
>> and then injected
>> public static ComponentMessagesSource
>> buildComponentMessagesSource(UpdateListenerHub updateListenerHub,
>> @Autobuild ComponentMessagesSourceImpl service)
>> {
>>    updateListenerHub.addUpdateListener(service);
>>    return service;
>> }
>> 
>> Thank you for your help :)
>> 
>> Best regards,
>> 
>>  <http://www.dfacto.ch/ <http://www.dfacto.ch/>>       Numa Schmeder    
>> www.dfacto.ch <http://www.dfacto.ch/>  <
>> http://www.dfacto.ch/ <http://www.dfacto.ch/>>
>> n...@dfacto.ch <mailto:n...@dfacto.ch> <mailto:n...@dfacto.ch 
>> <mailto:n...@dfacto.ch>>   |   M +41 79 538 30 01
>> 
>> DIGITAL STRATEGY   |   DESIGN   |   DEVELOPMENT

Reply via email to