Este conteúdo não está disponível no idioma selecionado.

16.2. Locales


Each user login session has an associated instance of java.util.Locale, which is available to the application as a component named locale. Under normal circumstances, setting the locale requires no special configuration. Seam delegates to JSF to determine the active locale as follows:
  • If a locale is associated with the HTTP request (the browser locale), and that locale is in the list of supported locales from faces-config.xml, use that locale for the rest of the session.
  • Otherwise, if a default locale was specified in the faces-config.xml, use that locale for the rest of the session.
  • Otherwise, use the default locale of the server.
You can set the locale manually through the Seam configuration properties org.jboss.seam.international.localeSelector.language, org.jboss.seam.international.localeSelector.country and org.jboss.seam.international.localeSelector.variant, but there is no good reason to use this method over those described above.
It is useful to allow the user to set the locale manually via the application user interface. Seam provides built-in functionality to override the locale determined by the default algorithm. Do this by adding the following fragment to a form in your JSP or Facelets page:
<h:selectOneMenu value="#{localeSelector.language}"> 
  <f:selectItem itemLabel="English" itemValue="en"/> 
  <f:selectItem itemLabel="Deutsch" itemValue="de"/> 
  <f:selectItem itemLabel="Francais" itemValue="fr"/> 
</h:selectOneMenu> 
<h:commandButton action="#{localeSelector.select}" 
                 value="#{messages['ChangeLanguage']}"/>
Copy to Clipboard Toggle word wrap
Or, if you want a list of all supported locales from faces-config.xml, use:
<h:selectOneMenu value="#{localeSelector.localeString}"> 
  <f:selectItems value="#{localeSelector.supportedLocales}"/> 
</h:selectOneMenu> 
<h:commandButton action="#{localeSelector.select}" 
                 value="#{messages['ChangeLanguage']}"/>
Copy to Clipboard Toggle word wrap
When the user selects an item from the drop-down, then clicks the command button, the Seam and JSF locales will be overridden for the rest of the session.
You can configure the supported locales and the default locale of the server with the built-in org.jboss.seam.international.localeConfig component. First, declare an XML namespace for Seam's international package in the Seam component descriptor. Then, define the default locale and supported locales as follows:
<international:locale-config default-locale="fr_CA" 
               supported-locales="en fr_CA fr_FR"/>
Copy to Clipboard Toggle word wrap
Remember that supported locales must have matching resource bundles. Next, define your language-specific labels.
Voltar ao topo
Red Hat logoGithubredditYoutubeTwitter

Aprender

Experimente, compre e venda

Comunidades

Sobre a documentação da Red Hat

Ajudamos os usuários da Red Hat a inovar e atingir seus objetivos com nossos produtos e serviços com conteúdo em que podem confiar. Explore nossas atualizações recentes.

Tornando o open source mais inclusivo

A Red Hat está comprometida em substituir a linguagem problemática em nosso código, documentação e propriedades da web. Para mais detalhes veja o Blog da Red Hat.

Sobre a Red Hat

Fornecemos soluções robustas que facilitam o trabalho das empresas em plataformas e ambientes, desde o data center principal até a borda da rede.

Theme

© 2025 Red Hat