the page does not load the JSF components
The page is loading the components, otherwise there won't be a <input type="text" />
that comes from the <p:inputText id="user" value="#{indexMB.user}" />
in your Facelets code (along with other components). The problem seems to be in your #{bundle['<whatever>']}
configuration. Note that this problem is not related to GlassFish nor TomEE at all, just about the internationalization configuration.
For JSF 2.x I followed the explanation from this Q/A: https://stackoverflow.com/a/4830669/1065197 and the link that provides more info: Internationalization in JSF with UTF-8 encoded properties files. Based in that tutorial I made a test application. In short:
Configure the bundle in your faces-config.xml
<application> <locale-config> <default-locale>pt_BR</default-locale> <supported-locale>en</supported-locale> <supported-locale>fr</supported-locale> </locale-config> <resource-bundle> <!-- Here should be the full name of the package and the name of the properties files with the i18n text. Example (from a personal project): edu.home.store.view.idioma.tienda Where the properties files are: edu.home.store.view.idioma.tienda_es.properties edu.home.store.view.idioma.tienda_en.properties --> <!-- <base-name>edu.home.store.view.idioma.tienda</base-name> --> <!-- assumming your file is directly posted in class folder --> <base-name>i18n</base-name> <!-- Name of the variable to use in Facelets files. --> <var>bundle</var> </resource-bundle> </application>
Create a
@SessionScoped
bean that will handle the locale to use in your pages.@ManagedBean @SessionScoped public class LocaleBean implements Serializable { private static final long serialVersionUID = 89794215646544L; private Locale locale; public LocaleBean() { } @PostConstruct public void init() { //give the default value here locale = new Locale("pt_BR"); FacesContext.getCurrentInstance().getViewRoot().setLocale(locale); } public Locale getLocale() { return locale; } public String getLenguaje() { return locale.getLanguage(); } public void setLenguaje(String lenguaje) { locale = new Locale(lenguaje); FacesContext.getCurrentInstance().getViewRoot().setLocale(locale); } }
Wrap all the content of your view using
<f:view>
and define the language to use. Preferably, this should go in the main template. Example:<f:view locale="#{localeBean.locale}"> <!-- Your Facelets code goes here... --> </f:view>
Apart from this problem, I highly recommend you to change the obviously autogenerated Faces Servlet
mapping configuration from /faces/*
to *.xhtml
:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
More info: