Getting locale on backing beans with multiple company using filter

Posted: July 24, 2013 in web

property files:

com.test.content_en_US
com.test.content_en_US_CompanyA
com.test.content_en_US_CompanyA_TX
com.test.content_en_US_CompanyA_NY
com.test.content_en_US_CompanyB
com.test.content_en_US_CompanyB_TX
com.test.content_en_US_CompanyB_NY

Filter:

...
Locale locale = new Locale("en", "US", "CompanyA");
        String host = request.getServerName();
        if (host.contains("companyB")) {
            locale = new Locale("en", "US", "CompanyB");
        }

        Config.set(request, Config.FMT_LOCALE, locale);
        request = new LocaleRequestWrapper((HttpServletRequest) request, locale);
        chain.doFilter(request, response);
...

Backing Bean:

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

public ResourceBundle getBundleByLocale(String state) {
        return ResourceBundle.getBundle('com.test.content',
                new Locale(locale.getLanguage(), locale.getCountry(), locale.getVariant() + "_" + state));
    }

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s