In an entity, I have an enumeration field which is translated in english and french.
In the same entity, I have a computed field that I am using as a toString, so I would like to build the computed field with the enumeration value translated in english or french, depending on the user's locale.
My question : in the getter of my computed field written in the extension of the entity, how could I get the user's locale and translate the enumeration value ?
You have to make your extension aware of its execution context. There are several interfaces that you can implement in your extensions so that they get injected with elements of their running context.
org.jspresso.framework.model.component.IComponentFactoryAware
to receive anICompoentFactory
instanceorg.jspresso.framework.security.ISubjectAware
to receive the instance of the logged-inSubject
org.jspresso.framework.application.backend.session.IApplicationSessionAware
to receive the current instance ofIApplicationSession
org.jspresso.framework.model.entity.IEntityLifecycleHandlerAware
to receive an instance ofIEntityLifecycleHandler
In order to fulfill your use-case, the 4th interface must be implemented. Your extension will be injected with an instance of
IEntityLifecycleHandler
through the following method :Just store this instance in your extension implementation as an instance parameter and use it afterwards in your code by safely casting it as a
org.jspresso.framework.application.IController
.For instance :
Just remember that the pattern for the I18N resource bundle key of enumerations is
${ENUM_NAME}.${ENUM_VALUE}
which is computed as thetranslationKey
local variable in the code above.