Friday, March 7, 2014

How to get Locale/Language in ADF BC, ADF Faces and using Expression language - Oracle ADF

Many times we might need get the locale of the user and may be manipulate the skins or business logic based on that. By default, ADF Faces determines the locale of the end user by inspecting the browser language settings.

Get the locale in ADF Business Components Java Class

import java.util.Locale;
import oracle.adf.share.ADFContext;

Locale locale = ADFContext.getCurrent().adfctx.getLocale();

Get the locale in ADF Managed Bean

import java.util.Locale;
import javax.faces.context.FacesContext;

Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();

Get the locale using expression language

#{facesContext.ViewRoot.locale.language}

Once we get the locale, we can get the user language using either of the below methods

  1. String userLang = locale.getLanguage();
  2. #{facesContext.ViewRoot.locale.language}


No comments:

Post a Comment