Search code examples
jsflocale

How to change the locale for one view in jsf?


there is a way to change the locale for especific view in jsf? i can try the locale via faces-config.xml, but i just wanna a specific view.

faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xi="http://www.w3.org/2001/XInclude"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">

    <application>
        <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
        <locale-config>
            <default-locale>es</default-locale>
            <supported-locale>ca</supported-locale>
            <supported-locale>en</supported-locale>
        </locale-config>    

Solution

  • You can set the locale on a per-view basis by nesting your content in a <f:view> tag that has one of its attributes, locale, for exactly this purpose:

    <f:view locale="#{localeBean.selectedlocale}">
    

    For more information consult Localization in JSF, how to remember selected locale per session instead of per request/view.