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
Get the locale in ADF Business Components Java Class
import java.util.Locale;
import oracle.adf.share.ADFContext;
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
- String userLang = locale.getLanguage();
- #{facesContext.ViewRoot.locale.language}
No comments:
Post a Comment