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

时间:2014-04-12 21:24:25

标签: java gwt vaadin vaadin7

如何将Vaadin7服务器推送应用于导航视图。基本上我想要更新MyView类表组件的日期。由于它是一个导航视图,它不像Vaadin中解释的那样工作。 还有其他方法可以从MyView类更新数据吗?例如在其中插入线程。

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
                }
            });
        }
    }
}

查看课程

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(""));
    }
}

1 个答案:

答案 0 :(得分:1)

在MyView中,您可以在MyUI中注册您的类实例。 因此,您可以访问MyView实例并进行更新。

但也许您应该在MyView内部运行后台线程? 在没有显示MyView时更新MyView是没有意义的......