Dynamic keys for Struts resources (i18n).
Problem: Status messages are returned via status codes (int) and localized messages should be retrieved via internationalized resource file in Struts directly in a JSP file (w/o touching a bean).
Solution: Expression Language (EL) solves the problem elegant.
Excerpt of the ApplicationResource.properties:
[code lang=“Java“]overview.lifeCycleStatusCode=Lifecycle overview.lifecycleStatusCode.1= overview.lifecycleStatusCode.2=Withdrawn overview.lifecycleStatusCode.3=Sent overview.lifecycleStatusCode.4=Approved overview.lifecycleStatusCode.5=Rejected[/code]
Excerpt of the according JSP file using struts-layout can be found here.
The bean:meassage tag searches the ApplicationResource resource bundle using localized prefixes for i18n. layout:collectionItem returns one element of a collection of beans. For the bean employeeLeaveRequest the property lifeCycleStatusCode returns values in the closed interval [1..5]. Each of the status codes is statically assigned and defined in the resource bundle. Thus no additional filter or methos are needed.Simple and elegant, eh?