6.15. PortletFaces Liferay Language Portlet Integration

In a normal JSF web application, the Locale that is used to display internationalized values is dictated by the locale specified in the end-user's web-browser. However, Liferay Portal permits the user to select a different locale (language) using the Language Portlet. The user's choice is ultimately saved as a languageId in the Liferay User object and is persisted to the database.

Liferay Portal Language Portlet

Figure 6.10. Liferay Portal Language Portlet


In order to provide seamless integration between JSF portlets and the language selected by the user, PortletFaces provides the LiferayLocalePhaseListener. The listener monitors the RESTORE_VIEW phase of the JSF lifecycle and will automatically set the locale inside the UIViewRoot according to the value specified by Liferay's User.getLocale() method, which is aware of the selected languageId. This in turn causes internationalization techniques such as the f:loadBundle tag and the i18n EL keyword to automatically translate message keys into the language selected by the user with the Liferay Language Portlet.