本文整理匯總了Java中com.vaadin.server.VaadinSession.setAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java VaadinSession.setAttribute方法的具體用法?Java VaadinSession.setAttribute怎麽用?Java VaadinSession.setAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.vaadin.server.VaadinSession
的用法示例。
在下文中一共展示了VaadinSession.setAttribute方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
}
示例2: 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();
}
示例3: onRequestEnd
import com.vaadin.server.VaadinSession; //導入方法依賴的package包/類
@Override
public void onRequestEnd(VaadinRequest request, VaadinResponse response, VaadinSession session) {
try {
if (session != null) {
SecurityContext securityContext = SecurityContextHolder.getContext();
logger.trace("Storing security context {} in VaadinSession {}", securityContext, session);
session.lock();
try {
session.setAttribute(SECURITY_CONTEXT_SESSION_ATTRIBUTE, securityContext);
} finally {
session.unlock();
}
} else {
logger.trace("No VaadinSession available for storing the security context");
}
} finally {
logger.trace("Clearing security context");
SecurityContextHolder.clearContext();
}
}
示例4: 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);
}
示例5: 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;
}
示例6: 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()));
}
}
}
示例7: 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;
}
示例8: 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);
}
}
示例9: 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;
}
示例10: show
import com.vaadin.server.VaadinSession; //導入方法依賴的package包/類
static void show(String message, Throwable throwable) {
VaadinSession session = VaadinSession.getCurrent();
session.setAttribute(ErrorView.PARAM_MESSAGE, message);
session.setAttribute(ErrorView.PARAM_THROWABLE, throwable);
UI.getCurrent().getNavigator().navigateTo(ErrorView.VIEW_NAME);
}
示例11: clearCache
import com.vaadin.server.VaadinSession; //導入方法依賴的package包/類
public void clearCache() {
VaadinSession session = VaadinSession.getCurrent();
session.setAttribute(SettingsClient.NAME, null);
}
示例12: init
import com.vaadin.server.VaadinSession; //導入方法依賴的package包/類
/**
* 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) {
//noinspection ThrowableResultOfMethodCallIgnored
log.error("Error handling exception\nOriginal exception:\n{}\nException in handlers:\n{}",
ExceptionUtils.getStackTrace(event.getThrowable()), ExceptionUtils.getStackTrace(e)
);
}
});
appLog = new AppLog();
connection = createConnection();
exceptionHandlers = new ExceptionHandlers(this);
cookies = new AppCookies();
themeConstants = loadTheme();
VaadinServlet vaadinServlet = VaadinServlet.getCurrent();
ServletContext sc = vaadinServlet.getServletContext();
String resourcesTimestamp = sc.getInitParameter("webResourcesTs");
if (StringUtils.isNotEmpty(resourcesTimestamp)) {
this.webResourceTimestamp = resourcesTimestamp;
}
log.debug("Initializing application");
// get default locale from config
Locale targetLocale = resolveLocale(requestLocale);
setLocale(targetLocale);
}
示例13: setAttribute
import com.vaadin.server.VaadinSession; //導入方法依賴的package包/類
public static <T> void setAttribute(Class<T> type, T value) {
VaadinSession session = VaadinSession.getCurrent();
if (session != null) {
session.setAttribute(type, value);
}
}
示例14: clearAttribute
import com.vaadin.server.VaadinSession; //導入方法依賴的package包/類
public static <T> void clearAttribute(Class<T> type) {
VaadinSession session = VaadinSession.getCurrent();
if (session != null) {
session.setAttribute(type, null);
}
}