You can see a working example of this in the addressbook-faces.war included in the download (with tutorial here), but in this blog entry I'll focus specifically on translated labels.
Metawidget generates labels for widgets based on...
- the uncamel-cased version of the property name (eg. 'Date of birth' for 'dateOfBirth')
- the exact text specified in the @UiLabel annotation (or label XML attribute)
- a bundle key based on the camel-cased version of the text specified in @UiLabel or label (eg. 'dateOfBirth' for 'Date of birth')
- a bundle key based on the property name
To add a bundle, you can either add one globally in faces-config.xml...
<application>
<message-bundle>com.myapp.Resources</message-bundle>
</application>
<message-bundle>com.myapp.Resources</message-bundle>
</application>
...or on the page...
<f:loadBundle basename="com.myapp.Resources" var="bundle"/>
...
<m:metawidget value="#{myBusinessObject}" bundle="#{bundle}"/>
...
<m:metawidget value="#{myBusinessObject}" bundle="#{bundle}"/>
...and that's it! The other supported Metawidgets (for Android, GWT, JSP, Spring, Struts, Swing, etc.) all do localization in a similar fashion, following the conventions of their particular platform.
0 comments:
Post a Comment