首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在vaadin中动态推送更新页面?

如何在vaadin中动态推送更新页面?
EN

Stack Overflow用户
提问于 2014-06-20 15:02:29
回答 1查看 939关注 0票数 0

我有一个使用VaadinSpring (+Security)的工作应用程序。我现在正尝试使用vaadin-push动态地将更新推送到客户端接口。

我想要创建一个对所有客户端都一样的“视图”。视图应该通过push获得一个动态递增的计数器。因此,当客户端显示页面时,计数器会自我更新(或者在我的示例中:向页面追加多个标签组件)。每个客户都应该看到相同的值。

但我没有看到这些变化被推到网页上。为什么?

代码语言:javascript
复制
//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:不能挂起超过会话超时的响应。在org.atmosphere.cpr.AtmosphereResourceImpl.suspend(AtmosphereResourceImpl.java:314) at org.atmosphere.cpr.AtmosphereResourceImpl.suspend(AtmosphereResourceImpl.java:292) at com.vaadin.server.communication.PushHandler$2.run(PushHandler.java:129) at com.vaadin.server.communication.PushHandler.callWithUi(PushHandler.java:242) at com.vaadin.server.communication.PushHandler.access$200(PushHandler.java:55)在web.xml中增加会话超时的值com.vaadin.server.communication.PushHandler$1.onRequest(PushHandler.java:73)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-24 07:11:26

基于https://github.com/peholmst/vaadin4spring/issues/51#issuecomment-46875255的解决方案

server.sessionTimeout=30@Push(transport = Transport.LONG_POLLING)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24330272

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档