/** * Creates and registers a new VaadinSession for this service. Assumes * proper locking has been taken care of by the caller. * * * @param request * The request which triggered session creation. * @return A new VaadinSession instance * @throws ServiceException */ private VaadinSession createAndRegisterSession(VaadinRequest request) throws ServiceException { assert ((ReentrantLock) getSessionLock(request.getWrappedSession())) .isHeldByCurrentThread() : "Session has not been locked by this thread"; VaadinSession session = createVaadinSession(request); VaadinSession.setCurrent(session); storeSession(session, request.getWrappedSession()); // Initial WebBrowser data comes from the request session.getBrowser().updateRequestDetails(request); // Initial locale comes from the request Locale locale = request.getLocale(); session.setLocale(locale); session.setConfiguration(getDeploymentConfiguration()); session.setCommunicationManager( new LegacyCommunicationManager(session)); ServletPortletHelper.initDefaultUIProvider(session, this); onVaadinSessionStarted(request, session); return session; }
private void updateVaadinLocale() { Locale locale = getLocale(); UI.getCurrent().setLocale(locale); VaadinSession.getCurrent().setLocale(locale); recursiveSetLocale(); }
/** * Called when <em>the first</em> UI of the session is initialized. */ protected void init(Locale requestLocale) { VaadinSession vSession = VaadinSession.getCurrent(); vSession.setAttribute(App.class, this); vSession.setLocale(messageTools.getDefaultLocale()); // set root error handler for all session vSession.setErrorHandler(event -> { try { getExceptionHandlers().handle(event); getAppLog().log(event); } catch (Throwable e) { log.error("Error handling exception\nOriginal exception:\n{}\nException in handlers:\n{}", ExceptionUtils.getStackTrace(event.getThrowable()), ExceptionUtils.getStackTrace(e) ); } }); log.debug("Initializing application"); appLog = new AppLog(webConfig.getAppLogMaxItemsCount(), beanLocator.get(TimeSource.NAME)); connection = createConnection(); exceptionHandlers = new ExceptionHandlers(this, beanLocator); cookies = new AppCookies(); themeConstants = loadTheme(); // get default locale from config Locale targetLocale = resolveLocale(requestLocale); setLocale(targetLocale); }
/** * @see com.vaadin.server.SessionInitListener#sessionInit(com.vaadin.server.SessionInitEvent) */ public void sessionInit(final SessionInitEvent event) { // set the locale to the users workplace locale Locale wpLocale = OpenCms.getWorkplaceManager().getWorkplaceLocale(getCmsObject()); event.getSession().setLocale(wpLocale); event.getSession().addRequestHandler(REQUEST_AUTHORIZATION_HANDLER); event.getSession().addUIProvider(LOGIN_UI_PROVIDER); event.getSession().addBootstrapListener(BOOTSTRAP_LISTENER); }
/** * Creates and registers a new VaadinSession for this service. Assumes * proper locking has been taken care of by the caller. * * * @param request * The request which triggered session creation. * @return A new VaadinSession instance * @throws ServiceException */ private VaadinSession createAndRegisterSession(VaadinRequest request) throws ServiceException { assert ((ReentrantLock) getSessionLock(request.getWrappedSession())) .isHeldByCurrentThread() : "Session has not been locked by this thread"; VaadinSession session = createVaadinSession(request); VaadinSession.setCurrent(session); storeSession(session, request.getWrappedSession()); // Initial WebBrowser data comes from the request session.getBrowser().updateRequestDetails(request); // Initial locale comes from the request Locale locale = request.getLocale(); session.setLocale(locale); session.setConfiguration(getDeploymentConfiguration()); onVaadinSessionStarted(request, session); return session; }
public void setLocale(Locale locale) { UserSession session = getConnection().getSession(); if (session != null) { session.setLocale(locale); } AppUI currentUi = AppUI.getCurrent(); // it can be null if we handle request in a custom RequestHandler if (currentUi != null) { currentUi.setLocale(locale); currentUi.updateClientSystemMessages(locale); } VaadinSession.getCurrent().setLocale(locale); for (AppUI ui : getAppUIs()) { if (ui != currentUi) { ui.accessSynchronously(() -> { ui.setLocale(locale); ui.updateClientSystemMessages(locale); }); } } }