ActionExecution + I18NUtil - messages are not included

cancel
Showing results for 
Search instead for 
Did you mean: 
p31r
Member II

ActionExecution + I18NUtil - messages are not included

Jump to solution

Hello guys,

We have just encounter strange "bug?" (is it bug or I am only dumb?)

We've implemented Custom Repo action - "SampleAction extends ActionExecuterAbstractBase()"

and call it with this sample (test call):

action = actionService.createAction(SampleAction.NAME)
action.setParameterValue(SampleAction.PARAM_QUERY, query)
action.setExecuteAsynchronously(true) // here is the problem when async is true
actionService.executeAction(action, null)

 Strange thing happens with asynchronous execution.

In code we try to retrieve localized messages from I18NUtil:

I18NUtil.getMessage("action.sample.msg")
// or
messageService.getMessage("action.sample.msg")

 When action is called with asynchronous=false -> everything is alright.

But when asynchronous=true -> I18NUtil or even messageService can not find the message (returns null)

I've tried debug through I18NUtil.getMessage() - seems that budles are there with messages, but can not retrieve the exact message

Status report: we debugged I18NUtil a little bit more: when called from the asynchronous action - our custom budles are cached, but messages from this context are not (not even one message from our custom bundles)

Message budles are registered as follows:

<bean id="custom.base.dictionaryBootstrap"
parent="dictionaryModelBootstrap"
depends-on="dictionaryBootstrap">
<property name="labels">
<list>
<value>alfresco.module.${project.artifactId}.messages.customActions</value>
</list>
</property>
</bean>

Any help would be appreciated.

Thanks

1 Solution

Accepted Solutions
p31r
Member II

Re: ActionExecution + I18NUtil - messages are not included

Jump to solution

Thanks for your reply.

Yeah, we though this aswell. But it seems that the I18NUtil is able to get proper Locale (messageService.getLocale() returns exact Locale from request header) even in asynchronous action.

 

SOLVED: so, we have played with this a little bit. Just try/error style.

Register bundles as:

<bean id="resourceBundles" class="org.alfresco.i18n.ResourceBundleBootstrapComponent">
<property name="resourceBundles">
<list>
<value>alfresco.module.${project.artifactId}.messages.customAction</value>
</list>
</property>
</bean>

seems to solve this problem. It looks like bundles are loaded differentyl from dictionaryBootstrap. The messages was really not cached in I18NUtil in asynchronous context.

Do not know if this is bug or not.

Thank you

View solution in original post

3 Replies
afaust
Master

Re: ActionExecution + I18NUtil - messages are not included

Jump to solution

Your problem probably has to do with the lack of the proper Locale in the context of I18nUtil. When you run an action in synchronous mode, the action and I18nUtil inherit the Locale context from the request thread, which typically is associated with the Locale as provided by the client browser. This context is not carried over to asynchronous actions, and as such, the I18nUtil may try to look up messages in different locales from the ones for which you have provided message bundles, and thus not find any matches.

p31r
Member II

Re: ActionExecution + I18NUtil - messages are not included

Jump to solution

Thanks for your reply.

Yeah, we though this aswell. But it seems that the I18NUtil is able to get proper Locale (messageService.getLocale() returns exact Locale from request header) even in asynchronous action.

 

SOLVED: so, we have played with this a little bit. Just try/error style.

Register bundles as:

<bean id="resourceBundles" class="org.alfresco.i18n.ResourceBundleBootstrapComponent">
<property name="resourceBundles">
<list>
<value>alfresco.module.${project.artifactId}.messages.customAction</value>
</list>
</property>
</bean>

seems to solve this problem. It looks like bundles are loaded differentyl from dictionaryBootstrap. The messages was really not cached in I18NUtil in asynchronous context.

Do not know if this is bug or not.

Thank you

EddieMay
Alfresco Employee

Re: ActionExecution + I18NUtil - messages are not included

Jump to solution

Hi @p31r ,

Glad to see you got it sorted - thanks also for reporting the solution, really helpful for others ecountering similar problems.

Best wishes,

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!