0

我有一个使用Vaadinand的工作应用程序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:无法将响应挂起超过会话超时。在 com.vaadin 的 org.atmosphere.cpr.AtmosphereResourceImpl.suspend(AtmosphereResourceImpl.java:292) 的 org.atmosphere.cpr.AtmosphereResourceImpl.suspend(AtmosphereResourceImpl.java:314) 的 web.xml 中增加 session-timeout 的值。 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) 在 com.vaadin.server.communication.PushHandler$1.onRequest(PushHandler.java:73)

4

1 回答 1

0

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

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

于 2014-06-24T07:11:26.567 回答