XWork : Localization
This page last changed on Jul 13, 2004 by unkyaku.
Any action can indicate that it supports localization by implementing com.opensymphony.xwork.TextProvider. To access a localized message, simply use one of the various getText() method calls. The default implementation for this is com.opensymphony.xwork.TextProviderSupport, which in turn relies on com.opensymphony.xwork.util.LocalizedTextUtil. Any Action that extends com.opensymphony.xwork.ActionSupport will automatically gain localization support via TextProviderSupport.In this implementation, when you attempt to look up a message, it attempts to do the following:
Default Resource Bundles.It is possible to register default resource bundles with XWork via LocalizedTextUtil.addDefaultResourceBundle().Message lookup in the default resource bundles is done in reverse order of their registration (i.e. the first resource bundle registered is the last to be searched). By default, one default resource bundle name is registered with LocalizedTextUtil – "com/opensymphony/xwork/xwork-messages" – which is bundled with the XWork jar file to provide system-level message texts.ExampleGiven a ModelDriven Action called BarnAction where getModel() returns a Horse object, and the Horse object has the following class structure:interface acme.test.Animal; class acme.test.AnimalImpl implements Animal; interface acme.test.Quadraped extends Animal; class acme.test.QuadrapedImpl extends Animal implements Quadraped; class acme.test.Horse extends QuadrapedImpl; Then the localization system will attempt to look up the message in the following resource bundles in this order: acme.test.BarnAction.properties acme.test.Horse.properties acme.test.QuadrapedImpl.properties acme.test.Quadraped.properties acme.test.AnimalImpl.properties acme.test.Animal.properties acme.test.package.properties acme.package.properties Message Key InterpolationWhen looking for the message, if the key indexes a collection (e.g. user.phone[0]) and a message for that specific key cannot be found, the general form will also be looked up (i.e. user.phone[*]).Message InterpolationIf a message is found, it will also be interpolated. Anything within ${...} will be treated as an OGNL expression and evaluated as such. |
![]() |
Document generated by Confluence on Dec 12, 2004 12:35 |