0

Hi I want to change the locale using javascript in the JSF.Can anyone give example.

Rakesh Sabbani
  • 1,655
  • 5
  • 17
  • 31

1 Answers1

3

Just let JavaScript send a HTTP request in some way (form.submit(), window.location, ajax, etc) so that JSF is able to do

String locale = getItAsRequestParameterOrSomething(); // "en", "en_US", etc
FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale(locale));

You can find a kickoff example which does that by a dropdown which is submitted by JS in this answer: Localization in JSF, how to remember selected locale per session instead of per request/view

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555