Example usage for org.springframework.web.servlet DispatcherServlet LOCALE_RESOLVER_BEAN_NAME

List of usage examples for org.springframework.web.servlet DispatcherServlet LOCALE_RESOLVER_BEAN_NAME

Introduction

In this page you can find the example usage for org.springframework.web.servlet DispatcherServlet LOCALE_RESOLVER_BEAN_NAME.

Prototype

String LOCALE_RESOLVER_BEAN_NAME

To view the source code for org.springframework.web.servlet DispatcherServlet LOCALE_RESOLVER_BEAN_NAME.

Click Source Link

Document

Well-known name for the LocaleResolver object in the bean factory for this namespace.

Usage

From source file:org.vaadin.webinars.springandvaadin.i18n.ui.Servlet.java

@Override
protected void servletInitialized() throws ServletException {
    final ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
    try {/*from  w w  w.  ja v  a  2s  .  c  o m*/
        localeResolver = context.getBean(DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME, LocaleResolver.class);
    } catch (NoSuchBeanDefinitionException e) {
        localeResolver = new SessionLocaleResolver();
    }
    getService().addSessionInitListener(new SessionInitListener() {
        @Override
        public void sessionInit(SessionInitEvent sessionInitEvent) throws ServiceException {
            sessionInitEvent.getSession().addUIProvider(new UIProvider() {
                @Override
                public Class<? extends UI> getUIClass(UIClassSelectionEvent uiClassSelectionEvent) {
                    return I18nUI.class;
                }

                @Override
                public UI createInstance(UICreateEvent event) {
                    return context.getBean(event.getUIClass());
                }
            });
        }
    });
}

From source file:com.github.peholmst.springsecuritydemo.servlet.SpringApplicationServlet.java

private void initLocaleResolver(ApplicationContext context) {
    try {// w ww.j  a v  a 2  s.com
        /*
         * Try to look up the locale resolver from the application context
         */
        localeResolver = context.getBean(DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME, LocaleResolver.class);
        if (logger.isInfoEnabled()) {
            logger.info("Using LocaleResolver [" + localeResolver + "]");
        }
    } catch (NoSuchBeanDefinitionException e) {
        /*
         * No locale resolver was defined in the application context, so we
         * create a default one.
         */
        localeResolver = new SessionLocaleResolver();
        if (logger.isWarnEnabled()) {
            logger.warn(
                    "Unable to locate LocaleResolver with name '" + DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME
                            + "', using default [" + localeResolver + "]");
        }
    }
}