當前位置: 首頁>>代碼示例>>Java>>正文


Java VaadinSession.getCurrent方法代碼示例

本文整理匯總了Java中com.vaadin.server.VaadinSession.getCurrent方法的典型用法代碼示例。如果您正苦於以下問題:Java VaadinSession.getCurrent方法的具體用法?Java VaadinSession.getCurrent怎麽用?Java VaadinSession.getCurrent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.vaadin.server.VaadinSession的用法示例。


在下文中一共展示了VaadinSession.getCurrent方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: get

import com.vaadin.server.VaadinSession; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public <T> Optional<T> get(String resourceKey, Class<T> resourceType) throws TypeMismatchException {
	ObjectUtils.argumentNotNull(resourceKey, "Resource key must be not null");
	ObjectUtils.argumentNotNull(resourceType, "Resource type must be not null");

	final VaadinSession session = VaadinSession.getCurrent();

	if (session != null) {

		Object value = session.getAttribute(resourceKey);
		if (value != null) {

			// check type
			if (!TypeUtils.isAssignable(value.getClass(), resourceType)) {
				throw new TypeMismatchException("<" + NAME + "> Actual resource type [" + value.getClass().getName()
						+ "] and required resource type [" + resourceType.getName() + "] mismatch");
			}

			return Optional.of((T) value);

		}
	}

	return Optional.empty();
}
 
開發者ID:holon-platform,項目名稱:holon-vaadin7,代碼行數:27,代碼來源:VaadinSessionScope.java

示例2: put

import com.vaadin.server.VaadinSession; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public <T> Optional<T> put(String resourceKey, T value) throws UnsupportedOperationException {
	ObjectUtils.argumentNotNull(resourceKey, "Resource key must be not null");

	final VaadinSession session = VaadinSession.getCurrent();
	if (session == null) {
		throw new IllegalStateException("Current VaadinSession not available");
	}

	Object exist = session.getAttribute(resourceKey);

	session.setAttribute(resourceKey, value);

	try {
		T previous = (T) exist;
		return Optional.ofNullable(previous);
	} catch (@SuppressWarnings("unused") Exception e) {
		// ignore
		return Optional.empty();
	}
}
 
開發者ID:holon-platform,項目名稱:holon-vaadin7,代碼行數:23,代碼來源:VaadinSessionScope.java

示例3: putIfAbsent

import com.vaadin.server.VaadinSession; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public <T> Optional<T> putIfAbsent(String resourceKey, T value) throws UnsupportedOperationException {
	ObjectUtils.argumentNotNull(resourceKey, "Resource key must be not null");

	final VaadinSession session = VaadinSession.getCurrent();
	if (session == null) {
		throw new IllegalStateException("Current VaadinSession not available");
	}

	if (value != null) {
		synchronized (session) {
			Object exist = session.getAttribute(resourceKey);
			if (exist == null) {
				session.setAttribute(resourceKey, value);
			} else {
				return Optional.of((T) exist);
			}
		}
	}

	return Optional.empty();
}
 
開發者ID:holon-platform,項目名稱:holon-vaadin7,代碼行數:24,代碼來源:VaadinSessionScope.java

示例4: initExpectations

import com.vaadin.server.VaadinSession; //導入方法依賴的package包/類
@Override
protected void initExpectations() {
    super.initExpectations();

    new NonStrictExpectations() {
        {
            vaadinSession.getLocale(); result = Locale.ENGLISH;
            VaadinSession.getCurrent(); result = vaadinSession;

            globalConfig.getAvailableLocales(); result = ImmutableMap.of("en", Locale.ENGLISH);
            AppContext.getProperty("cuba.mainMessagePack"); result = "com.haulmont.cuba.web";
        }
    };

    factory = new WebComponentsFactory();
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:17,代碼來源:WebDateFieldTest.java

示例5: enter

import com.vaadin.server.VaadinSession; //導入方法依賴的package包/類
@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
    Label errorLabel = new Label("エラーが発生しました。");
    errorLabel.setStyleName(ValoTheme.LABEL_FAILURE);

    VaadinSession session = VaadinSession.getCurrent();
    String paramMessage = (String) session.getAttribute(PARAM_MESSAGE);
    if (paramMessage != null) {
        addComponent(new Label(paramMessage));
    }
    session.setAttribute(PARAM_MESSAGE, null);
    Throwable paramThrowable = (Throwable) session.getAttribute(PARAM_THROWABLE);
    if (paramThrowable != null) {
        addComponent(new Label(throwable2html(paramThrowable), ContentMode.HTML));
    }
    session.setAttribute(PARAM_THROWABLE, null);
    log.error(paramMessage, paramThrowable);

    if (paramThrowable instanceof AuthenticationException) {
        Button loginButton = new Button("ログイン", click -> getUI().getNavigator().navigateTo(LoginView.VIEW_NAME));
        addComponent(loginButton);
        setComponentAlignment(loginButton, Alignment.MIDDLE_CENTER);
    }

    Button homeButton = new Button("ホーム", click -> getUI().getNavigator().navigateTo(FrontView.VIEW_NAME));
    addComponent(homeButton);
    setComponentAlignment(homeButton, Alignment.MIDDLE_CENTER);
}
 
開發者ID:JavaTrainingCourse,項目名稱:obog-manager,代碼行數:29,代碼來源:ErrorView.java

示例6: remove

import com.vaadin.server.VaadinSession; //導入方法依賴的package包/類
@Override
public boolean remove(String resourceKey) throws UnsupportedOperationException {
	ObjectUtils.argumentNotNull(resourceKey, "Resource key must be not null");

	final VaadinSession session = VaadinSession.getCurrent();
	if (session == null) {
		throw new IllegalStateException("Current VaadinSession not available");
	}

	Object exist = session.getAttribute(resourceKey);
	session.setAttribute(resourceKey, null);

	return exist != null;
}
 
開發者ID:holon-platform,項目名稱:holon-vaadin7,代碼行數:15,代碼來源:VaadinSessionScope.java

示例7: getCurrentMFSession

import com.vaadin.server.VaadinSession; //導入方法依賴的package包/類
public static final MFSession getCurrentMFSession()
{
	final VaadinSession vaadinSession = VaadinSession.getCurrent();
	if (vaadinSession == null)
	{
		return null;
	}
	return vaadinSession.getAttribute(MFSession.class);
}
 
開發者ID:metasfresh,項目名稱:metasfresh-procurement-webui,代碼行數:10,代碼來源:MFProcurementUI.java

示例8: get

import com.vaadin.server.VaadinSession; //導入方法依賴的package包/類
@Override
public Object get(String name, ObjectFactory<?> objectFactory) {
    if (VaadinSession.getCurrent() == null || !VaadinSession.getCurrent().hasLock()) {
        throw new IllegalStateException("Unable to use VaadinSessionScope from non-Vaadin thread");
    }

    Object object = VaadinSession.getCurrent().getAttribute(name);
    if (object == null) {
        object = objectFactory.getObject();
        VaadinSession.getCurrent().setAttribute(name, object);
    }
    return object;
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:14,代碼來源:VaadinSessionScope.java

示例9: remove

import com.vaadin.server.VaadinSession; //導入方法依賴的package包/類
@Override
public Object remove(String name) {
    if (VaadinSession.getCurrent() == null || !VaadinSession.getCurrent().hasLock()) {
        throw new IllegalStateException("Unable to use VaadinSessionScope from non-Vaadin thread");
    }

    Object bean = VaadinSession.getCurrent().getAttribute(name);
    VaadinSession.getCurrent().setAttribute(name, null);
    return bean;
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:11,代碼來源:VaadinSessionScope.java

示例10: getConversationId

import com.vaadin.server.VaadinSession; //導入方法依賴的package包/類
@Override
public String getConversationId() {
    if (VaadinSession.getCurrent() == null || !VaadinSession.getCurrent().hasLock()) {
        throw new IllegalStateException("Unable to use VaadinSessionScope from non-Vaadin thread");
    }

    return VaadinSession.getCurrent().getSession().getId();
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:9,代碼來源:VaadinSessionScope.java

示例11: get

import com.vaadin.server.VaadinSession; //導入方法依賴的package包/類
@Override
public SecurityContext get() {
    VaadinSession vaadinSession = VaadinSession.getCurrent();
    if (vaadinSession != null && vaadinSession.hasLock()) {
        return vaadinSession.getAttribute(SecurityContext.class);
    }

    return super.get();
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:10,代碼來源:WebVaadinCompatibleSecurityContextHolder.java

示例12: set

import com.vaadin.server.VaadinSession; //導入方法依賴的package包/類
@Override
public void set(SecurityContext securityContext) {
    VaadinSession vaadinSession = VaadinSession.getCurrent();
    if (vaadinSession != null && vaadinSession.hasLock()) {
        vaadinSession.setAttribute(SecurityContext.class, securityContext);
    } else {
        super.set(securityContext);
    }
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:10,代碼來源:WebVaadinCompatibleSecurityContextHolder.java

示例13: getCache

import com.vaadin.server.VaadinSession; //導入方法依賴的package包/類
protected Map<String, Optional<String>> getCache() {
    VaadinSession session = VaadinSession.getCurrent();
    @SuppressWarnings("unchecked")
    Map<String, Optional<String>> settings = (Map<String, Optional<String>>) session.getAttribute(SettingsClient.NAME);
    if (settings == null) {
        settings = new ConcurrentHashMap<>();
        session.setAttribute(SettingsClient.NAME, settings);
    }
    return settings;
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:11,代碼來源:WebSettingsClient.java

示例14: getInstance

import com.vaadin.server.VaadinSession; //導入方法依賴的package包/類
/**
 * @return Current App instance. Can be invoked anywhere in application code.
 * @throws IllegalStateException if no application instance is bound to the current {@link VaadinSession}
 */
public static App getInstance() {
    VaadinSession vSession = VaadinSession.getCurrent();
    if (vSession == null) {
        throw new IllegalStateException("No VaadinSession found");
    }
    App app = vSession.getAttribute(App.class);
    if (app == null) {
        throw new IllegalStateException("No App is bound to the current VaadinSession");
    }
    return app;
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:16,代碼來源:App.java

示例15: checkUIAccess

import com.vaadin.server.VaadinSession; //導入方法依賴的package包/類
@Override
public void checkUIAccess() {
    VaadinSession vaadinSession = VaadinSession.getCurrent();

    if (vaadinSession == null || !vaadinSession.hasLock()) {
        throw new IllegalConcurrentAccessException();
    }
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:9,代碼來源:WebBackgroundWorker.java


注:本文中的com.vaadin.server.VaadinSession.getCurrent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。