Java Code Examples for com.vaadin.server.VaadinSession#setAttribute()
The following examples show how to use
com.vaadin.server.VaadinSession#setAttribute() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VaadinSessionScope.java From cuba with Apache License 2.0 | 5 votes |
@Override public Object get(String name, ObjectFactory<?> objectFactory) { VaadinSession session = VaadinSession.getCurrent(); if (session == null || !session.hasLock()) { throw new IllegalStateException("Unable to use VaadinSessionScope from non-Vaadin thread"); } Object object = session.getAttribute(name); if (object == null) { object = objectFactory.getObject(); session.setAttribute(name, object); } return object; }
Example 2
Source File: VaadinSessionScope.java From cuba with Apache License 2.0 | 5 votes |
@Override public Object remove(String name) { VaadinSession session = VaadinSession.getCurrent(); if (session == null || !session.hasLock()) { throw new IllegalStateException("Unable to use VaadinSessionScope from non-Vaadin thread"); } Object bean = session.getAttribute(name); session.setAttribute(name, null); return bean; }
Example 3
Source File: WebVaadinCompatibleSecurityContextHolder.java From cuba with Apache License 2.0 | 5 votes |
@Override public void set(SecurityContext securityContext) { VaadinSession vaadinSession = VaadinSession.getCurrent(); if (vaadinSession != null && vaadinSession.hasLock()) { vaadinSession.setAttribute(SecurityContext.class, securityContext); } else { super.set(securityContext); } }
Example 4
Source File: WebSettingsClient.java From cuba with Apache License 2.0 | 5 votes |
public void clearCache() { VaadinSession session = VaadinSession.getCurrent(); if (session == null || !session.hasLock()) { throw new IllegalConcurrentAccessException("Illegal access to settings client from background thread"); } session.setAttribute(SettingsClient.NAME, null); }
Example 5
Source File: WebSettingsClient.java From cuba with Apache License 2.0 | 5 votes |
protected Map<String, Optional<String>> getCache() { VaadinSession session = VaadinSession.getCurrent(); if (session == null || !session.hasLock()) { throw new IllegalConcurrentAccessException("Illegal access to settings client from background thread"); } @SuppressWarnings("unchecked") Map<String, Optional<String>> settings = (Map<String, Optional<String>>) session.getAttribute(SettingsClient.NAME); if (settings == null) { settings = new HashMap<>(); session.setAttribute(SettingsClient.NAME, settings); } return settings; }
Example 6
Source File: App.java From cuba with Apache License 2.0 | 5 votes |
/** * 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); }
Example 7
Source File: TestUiEnvironment.java From cuba with Apache License 2.0 | 4 votes |
protected void setupVaadinUi() { AutowireCapableBeanFactory injector = getInjector(); app = new DefaultApp(); setThemeConstants(app, new ThemeConstants(new HashMap<>())); setCookies(app, new AppCookies()); Connection connection = new ConnectionImpl(); injector.autowireBean(connection); setConnection(app, connection); VaadinSession vaadinSession = new TestVaadinSession(new WebBrowser(), getLocale()); vaadinSession.setAttribute(App.class, app); vaadinSession.setAttribute(App.NAME, app); vaadinSession.setAttribute(Connection.class, connection); vaadinSession.setAttribute(Connection.NAME, connection); vaadinSession.setAttribute(UserSession.class, sessionSource.getSession()); VaadinSession.setCurrent(vaadinSession); injector.autowireBean(app); ui = new AppUI(); injector.autowireBean(ui); // setup UI ConnectorTracker connectorTracker = new TestConnectorTracker(ui); try { getDeclaredField(UI.class, "connectorTracker", true) .set(ui, connectorTracker); getDeclaredField(UI.class, "session", true) .set(ui, vaadinSession); } catch (Exception e) { throw new RuntimeException("Unable to init Vaadin UI state", e); } UI.setCurrent(ui); VaadinRequest vaadinRequest = new TestVaadinRequest(); ui.getPage().init(vaadinRequest); initUi(ui, vaadinRequest); }