List of usage examples for com.vaadin.server VaadinSession getCurrent
public static VaadinSession getCurrent()
From source file:com.haulmont.cuba.web.App.java
License:Apache License
public void setLocale(Locale locale) { UserSession session = getConnection().getSession(); if (session != null) { session.setLocale(locale);/*from www. jav a2 s.c om*/ } 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); }); } } }
From source file:com.haulmont.cuba.web.DefaultApp.java
License:Apache License
protected void redirectAfterLogout(String loggedOutUrl) { if (!Strings.isNullOrEmpty(loggedOutUrl)) { AppUI currentUi = AppUI.getCurrent(); // it can be null if we handle request in a custom RequestHandler if (currentUi != null) { currentUi.setContent(null);//from w w w .j av a 2 s . c om currentUi.getPage().setLocation(loggedOutUrl); } else { VaadinResponse response = VaadinService.getCurrentResponse(); try { ((VaadinServletResponse) response).getHttpServletResponse().sendRedirect(loggedOutUrl); } catch (IOException e) { log.error("Error on send redirect to client", e); } } VaadinSession vaadinSession = VaadinSession.getCurrent(); for (UI ui : vaadinSession.getUIs()) { if (ui != currentUi) { ui.access(() -> { ui.setContent(null); ui.getPage().setLocation(loggedOutUrl); }); } } } }
From source file:com.haulmont.cuba.web.DefaultApp.java
License:Apache License
protected void preventSessionFixation(Connection connection, UserSession userSession) { if (connection.isAuthenticated() && !isLoggedInWithExternalAuth(userSession) && webConfig.getUseSessionFixationProtection() && VaadinService.getCurrentRequest() != null) { VaadinService.reinitializeSession(VaadinService.getCurrentRequest()); WrappedSession session = VaadinSession.getCurrent().getSession(); int timeout = webConfig.getHttpSessionExpirationTimeoutSec(); session.setMaxInactiveInterval(timeout); HttpSession httpSession = session instanceof WrappedHttpSession ? ((WrappedHttpSession) session).getHttpSession() : null;// w w w . j av a 2 s .com log.debug("Session reinitialized: HttpSession={}, timeout={}sec, UserSession={}", httpSession, timeout, connection.getSession()); } }
From source file:com.haulmont.cuba.web.gui.components.converters.StringToDatatypeConverter.java
License:Apache License
@Override public Object convertToModel(String value, Class<?> targetType, Locale locale) throws ConversionException { try {//from ww w. ja va2 s . c o m if (locale == null) { locale = VaadinSession.getCurrent().getLocale(); } if (isTrimming()) { value = StringUtils.trimToEmpty(value); } if (locale != null) { return datatype.parse(value, locale); } return datatype.parse(value); } catch (ParseException e) { throw new ConversionException(e); } }
From source file:com.haulmont.cuba.web.gui.components.converters.StringToDatatypeConverter.java
License:Apache License
@Override public String convertToPresentation(Object value, Class<? extends String> targetType, Locale locale) throws ConversionException { if (getFormatter() != null) { return getFormatter().format(value); }/* ww w . ja v a 2 s. c om*/ if (locale == null) { locale = VaadinSession.getCurrent().getLocale(); } if (locale != null) { return datatype.format(value, locale); } return datatype.format(value); }
From source file:com.haulmont.cuba.web.gui.components.converters.StringToEnumConverter.java
License:Apache License
@Override public Enum convertToModel(String value, Class<? extends Enum> targetType, Locale locale) throws ConversionException { if (value == null) { return null; }/*from w w w . j a v a2 s.co m*/ if (locale == null) { locale = VaadinSession.getCurrent().getLocale(); } if (isTrimming()) { value = StringUtils.trimToEmpty(value); } Object[] enumConstants = enumClass.getEnumConstants(); if (enumConstants != null) { for (Object enumValue : enumConstants) { if (Objects.equals(value, messages.getMessage((Enum) enumValue, locale))) { return (Enum) enumValue; } } } return null; }
From source file:com.haulmont.cuba.web.gui.components.converters.StringToEnumConverter.java
License:Apache License
@Override public String convertToPresentation(Enum value, Class<? extends String> targetType, Locale locale) throws ConversionException { if (getFormatter() != null) { return getFormatter().format(value); }//from ww w. j a va 2 s.c o m if (value == null) { return null; } if (locale == null) { locale = VaadinSession.getCurrent().getLocale(); } return messages.getMessage(value, locale); }
From source file:com.haulmont.cuba.web.gui.executors.impl.WebBackgroundWorker.java
License:Apache License
@Override public void checkUIAccess() { VaadinSession vaadinSession = VaadinSession.getCurrent(); if (vaadinSession == null || !vaadinSession.hasLock()) { throw new IllegalConcurrentAccessException(); }/*from w w w .j a v a2 s . c o m*/ }
From source file:com.haulmont.cuba.web.security.ConnectionImpl.java
License:Apache License
protected WebBrowser getWebBrowserDetails() { // timezone info is passed only on VaadinSession creation WebBrowser webBrowser = VaadinSession.getCurrent().getBrowser(); VaadinRequest currentRequest = VaadinService.getCurrentRequest(); // update web browser instance if current request is not null // it can be null in case of background/async processing of login request if (currentRequest != null) { webBrowser.updateRequestDetails(currentRequest); }//from w w w . j av a2 s .co m return webBrowser; }
From source file:com.haulmont.cuba.web.security.ConnectionImpl.java
License:Apache License
protected ClientUserSession getSessionInternal() { return (ClientUserSession) VaadinSession.getCurrent().getAttribute(UserSession.class); }