如何将 Vaadin7 服务器推送应用到导航 View 。基本上我想更新 MyView 类表组件。因为它是一个导航 View ,所以它不像 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(""));
}
}
最佳答案
在 MyView 中,您可以在 MyUI 中注册您的类实例。 因此,您可以访问 MyView 实例并更新它。
但也许您应该让后台线程在 MyView 中运行? 未显示时更新 MyView 没有意义...
关于java - 如何将 Vaadin 7 服务器推送应用到导航 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23036291/