当前位置: 首页>>代码示例>>Java>>正文


Java VaadinSession.getAttribute方法代码示例

本文整理汇总了Java中com.vaadin.server.VaadinSession.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java VaadinSession.getAttribute方法的具体用法?Java VaadinSession.getAttribute怎么用?Java VaadinSession.getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.vaadin.server.VaadinSession的用法示例。


在下文中一共展示了VaadinSession.getAttribute方法的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: closeUserVaadinSessions

import com.vaadin.server.VaadinSession; //导入方法依赖的package包/类
private void closeUserVaadinSessions(String loginName) {
    // CopyOnWriteArrayList is thread safe for iteration under update
    for (HttpSession session : this.sessions) {
        for (VaadinSession vaadinSession : VaadinSession.getAllSessions(session)) {
            Object userName = vaadinSession.getAttribute("user");
            if (loginName == null || loginName.equals(userName)) {
            	vaadinSession.close();

            	// Redirect all UIs to force the close
            	for (UI ui : vaadinSession.getUIs()) {
            		ui.access(() -> {
            			ui.getPage().setLocation("/");
            		});
	}
            }
        }
    }
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:19,代码来源:UiListenerDelegate.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: getCurrent

import com.vaadin.server.VaadinSession; //导入方法依赖的package包/类
public static TripMap getCurrent() {
    // Fetch from a session attribute as a workaround for not missing UI
    // scope support
    UI ui = UI.getCurrent();
    VaadinSession session = ui.getSession();

    String attributeName = TripMap.class.getName() + ui.getUIId();
    TripMap directionSearch = (TripMap) session
            .getAttribute(attributeName);
    if (directionSearch == null) {
        directionSearch = new TripMap();
        ui.getSession().setAttribute(attributeName, directionSearch);
    }
    return directionSearch;
}
 
开发者ID:vaadin,项目名称:trippy,代码行数:16,代码来源:TripMap.java

示例8: ensureInited

import com.vaadin.server.VaadinSession; //导入方法依赖的package包/类
/**
 * Ensure that a {@link DeviceInfo} is available from given Vaadin <code>session</code>. For successful
 * initialization, a {@link VaadinService#getCurrentRequest()} must be available.
 * @param session Vaadin session (not null)
 */
static void ensureInited(VaadinSession session) {
	ObjectUtils.argumentNotNull(session, "VaadinSession must be not null");
	synchronized (session) {
		if (session.getAttribute(SESSION_ATTRIBUTE_NAME) == null && VaadinService.getCurrentRequest() != null) {
			session.setAttribute(SESSION_ATTRIBUTE_NAME, create(VaadinService.getCurrentRequest()));
		}
	}
}
 
开发者ID:holon-platform,项目名称:holon-vaadin,代码行数:14,代码来源:DeviceInfo.java

示例9: 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

示例10: getCurrent

import com.vaadin.server.VaadinSession; //导入方法依赖的package包/类
public static final SwipeHelper getCurrent()
{
	final VaadinSession session = UI.getCurrent().getSession();
	SwipeHelper swipe = session.getAttribute(SwipeHelper.class);
	if (swipe == null)
	{
		swipe = new SwipeHelper();
		session.setAttribute(SwipeHelper.class, swipe);
	}
	return swipe;
}
 
开发者ID:metasfresh,项目名称:metasfresh-procurement-webui,代码行数:12,代码来源:SwipeHelper.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: 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

示例13: 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

示例14: onRequestStart

import com.vaadin.server.VaadinSession; //导入方法依赖的package包/类
@Override
public void onRequestStart(VaadinRequest request, VaadinResponse response) {
    final WrappedSession wrappedSession = request.getWrappedSession(false);
    VaadinSession session = null;
    if (wrappedSession != null) {
        session = VaadinSession.getForSession(request.getService(), wrappedSession);
    }

    SecurityContextHolder.clearContext();
    if (session != null) {
        logger.trace("Loading security context from VaadinSession {}", session);
        SecurityContext securityContext;
        session.lock();
        try {
            securityContext = (SecurityContext) session.getAttribute(SECURITY_CONTEXT_SESSION_ATTRIBUTE);
        } finally {
            session.unlock();
        }
        if (securityContext == null) {
            logger.trace("No security context found in VaadinSession {}", session);
        } else {
            logger.trace("Setting security context to {}", securityContext);
            SecurityContextHolder.setContext(securityContext);
        }
    } else {
        logger.trace("No VaadinSession available for retrieving the security context");
    }
}
 
开发者ID:peholmst,项目名称:vaadin4spring,代码行数:29,代码来源:SecurityContextVaadinRequestListener.java

示例15: getAttribute

import com.vaadin.server.VaadinSession; //导入方法依赖的package包/类
public static <T> T getAttribute(Class<T> type) {
	VaadinSession session = VaadinSession.getCurrent();
	if (session != null) {
		return session.getAttribute(type);
	}
	return null;
}
 
开发者ID:tilioteo,项目名称:hypothesis,代码行数:8,代码来源:SessionUtils.java


注:本文中的com.vaadin.server.VaadinSession.getAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。