【发布时间】:2014-06-20 15:02:29
【问题描述】:
我有一个使用 Vaadin 和 Spring (+Security) 的工作应用程序。我现在正在尝试使用 vaadin-push 将更新动态推送到客户端界面。
我想为所有客户创建一个相同的“视图”。视图应该得到一个通过推送动态递增的计数器。因此,当客户端显示页面时,计数器会自行更新(或者在我的示例中:将多个标签组件附加到页面)。每个客户都应该看到相同的值。
但我没有看到推送到网页的更改。为什么?
//the static controller the dynamically changes content
@Controller
public class ViewPresenter {
private static int counter = 0;
@Autowired
private void StaticView view;
@Scheduled(fixedRate = 1000)
public void refresh() {
//push the content change periodically to frontend
view.getUI().access(new Runnable() {
@Override
public void run() {
view.addComponent(new Label("refresh: " + counter++);
Sysout("update executed: " + counter); //OK, is printed
}
});
}
}
//the static test component that gets a new label added on every content change
@VaadinComponent
public class StaticView extends CssLayout {
//this is the view that every client should see
}
//the secured admin view
@VaadinView(name = "/secured")
@Scope("ui")
@Secured("user")
public class SecuredView extends VerticalLayout implements View {
@Autowired
private StaticView staticView;
@Override
public void enter(ViewChangeEvent event) {
addComponent(staticView);
}
}
//enable push
@Configuration
@Push
public class AppConfig {
}
@VaadinUI
@PreserveOnRefresh
public class ApplicationUI extends UI {
}
只有手动刷新网页才能看到客户端的变化。但内容本身不会自动改变。
也许@Push 必须放在UI 类上?但在这种情况下,我会收到以下错误:
java.lang.IllegalStateException:不能将响应挂起超过 会话超时。在 web.xml 中增加 session-timeout 的值 在 org.atmosphere.cpr.AtmosphereResourceImpl.suspend(AtmosphereResourceImpl.java:314) 在 org.atmosphere.cpr.AtmosphereResourceImpl.suspend(AtmosphereResourceImpl.java:292) 在 com.vaadin.server.communication.PushHandler$2.run(PushHandler.java:129) 在 com.vaadin.server.communication.PushHandler.callWithUi(PushHandler.java:242) 在 com.vaadin.server.communication.PushHandler.access$200(PushHandler.java:55) 在 com.vaadin.server.communication.PushHandler$1.onRequest(PushHandler.java:73)
【问题讨论】:
标签: java spring vaadin vaadin-push