Locale managed Bean in JSF 2.0

package beans;

 * @version 1.0
 * @author Med
import java.util.Locale;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

public class LocaleBean {

     * The Locale value is retrieved from the JSF view root.
    private Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();

     * @return the locale
    public Locale getLocale() {
        return locale;

     * @return The language from the locale
    public String getLanguage() {
        return locale.getLanguage();

     * Setter for the locale langue | It sets the locale that takes language as a parameter to the JSF View Root
     * @param language
    public void setLanguage(String language) {
        locale = new Locale(language);


One thought on “Locale managed Bean in JSF 2.0

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s