简体   繁体   English

如何将Vaadin 7服务器推送应用到导航视图

[英]How to apply Vaadin 7 server push to a Navigated View

How do I apply Vaadin7 server push to a Navigated View. 如何将Vaadin7服务器推送应用到导航视图。 Basically I want to up date MyView class table components. 基本上,我想更新MyView类表组件。 Since Its a navigated View its not working as explained in Vaadin. 由于它是导航视图,因此无法按照Va​​adin中的说明进行操作。 Is there Any other way to update data from MyView class? 还有其他方法可以从MyView类更新数据吗? such as inserting the thread in it. 例如将线程插入其中。

UI class UI类

@Push
public class MyUI extends UI{

Navigator  navigator;

@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = MyUI.class, widgetset = "com.example.myui.MyuiWidgetset")
public static class Servlet extends VaadinServlet {
}
    @Override
    protected void init(VaadinRequest request) {
        new Navigator(this, this);
        getNavigator().addView(MyView.MYVIEW, MyView.class);
        new InitializerThread().start();
    }
}

class InitializerThread extends Thread {
        @Override
        public void run() {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }

            access(new Runnable() {
                @Override
                public void run() {
                   //update MyView's table from this event
                }
            });
        }
    }
}

View Class 查看课程

public class MyView extends CustomComponent implements View
{
    public MainView()
    {
    final Table table = new Table();
    table.addContainerProperty("Date & Time", String.class, null);
    table.setSelectable(true);
    table.setSizeFull();
    table.setImmediate(true);

    while(){
      table.addItem(new Object[]{new Date()}, new String(""));
    }
}

In MyView you can register your class instance in MyUI. 在MyView中,您可以在MyUI中注册您的类实例。 So you have then access to the MyView instance and update it. 这样您就可以访问MyView实例并进行更新。

But perhaps you should have the background thread running inside of MyView instead? 但是也许您应该让后台线程在MyView内部运行? It does not make sense to update MyView when it's not displayed... 不显示MyView时更新它是没有意义的...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM