如何ServletContext
从我的Vaadin 7应用程序中访问当前的数据?
我想使用ServletContext
对象的setAttribute
,getAttribute
,removeAttribute
,和getAttributeNames
方法来管理全球一些国家对我的Vaadin应用程序.
此外,如果为此目的使用这些方法不适合Vaadin应用程序,请解释.
我对@PreserveOnRefresh注释的目的有疑问.这个特定注释的目的是什么?它必须使用的场景是什么?使用/不使用此注释有什么影响?
谢谢,Daniccan副总裁
我知道调用setAttribute(link)时有必要,但getAttirbute呢?
它是否正确?
public Object getMyAttribute() {
return VaadinSession.getCurrent().getAttribute("myAttribute");
}
Run Code Online (Sandbox Code Playgroud)
还是需要锁定?
public Object getMyAttribute() {
try {
VaadinSession.getCurrent().getLockInstance().lock();
return VaadinSession.getCurrent().getAttribute("myAttribute");
} finally {
VaadinSession.getCurrent().getLockInstance().unlock();
}
}
Run Code Online (Sandbox Code Playgroud)