Search in sources :

Example 41 with UIViewRoot

use of javax.faces.component.UIViewRoot in project deltaspike by apache.

the class JsfAwareLocaleResolver method getLocale.

@Override
public Locale getLocale() {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    if (facesContext != null && facesContext.getCurrentPhaseId() != null) {
        UIViewRoot viewRoot = facesContext.getViewRoot();
        Locale result = null;
        if (viewRoot != null) {
            // if a ViewRoot is present we return the Locale from there
            result = viewRoot.getLocale();
        }
        if (result != null) {
            Iterator<Locale> supportedLocale = facesContext.getApplication().getSupportedLocales();
            boolean supportedLocaleConfigured = false;
            while (supportedLocale.hasNext()) {
                supportedLocaleConfigured = true;
                if (result.equals(supportedLocale.next())) {
                    return result;
                }
            }
            if (!supportedLocaleConfigured) {
                return result;
            }
        }
        result = facesContext.getApplication().getDefaultLocale();
        if (result != null) {
            return result;
        }
    }
    // return the default Locale, if no Locale was found
    return super.getLocale();
}
Also used : Locale(java.util.Locale) FacesContext(javax.faces.context.FacesContext) UIViewRoot(javax.faces.component.UIViewRoot)

Aggregations

UIViewRoot (javax.faces.component.UIViewRoot)41 FacesContext (javax.faces.context.FacesContext)18 Test (org.junit.Test)10 ViewHandler (javax.faces.application.ViewHandler)8 Locale (java.util.Locale)6 ResourceBundle (java.util.ResourceBundle)4 Application (javax.faces.application.Application)3 UIComponent (javax.faces.component.UIComponent)3 ViewConfigDescriptor (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Map (java.util.Map)2 ExternalContext (javax.faces.context.ExternalContext)2 FacesContextFactory (javax.faces.context.FacesContextFactory)2 PreDestroyViewMapEvent (javax.faces.event.PreDestroyViewMapEvent)2 LifecycleFactory (javax.faces.lifecycle.LifecycleFactory)2 ServletContext (javax.servlet.ServletContext)2 NonNull (org.springframework.lang.NonNull)2 Handler (com.sun.jsftemplating.annotation.Handler)1 ModuleException (it.vige.rubia.ModuleException)1 ToHTMLConfig (it.vige.rubia.format.render.bbcodehtml.ToHTMLConfig)1