简体   繁体   English

Vaadin UI从其他线程更改UI组件时未更新

[英]Vaadin UI not updating while changing UI components from another thread

I've got the following code snippet in a normal private function, which is called from another method in the same class (the class is called AdministrationComponent which extends CustomComponent ). 我在普通的私有函数中有以下代码片段,该代码片段是从同一类的另一种方法调用的(该类称为AdministrationComponent ,它extends CustomComponent )。 This component is added to a TabBarView . 此组件已添加到TabBarView My problem is, that the three labels you can see in the code are not updated. 我的问题是,您在代码中看到的三个标签没有更新。

new Thread(new Runnable()
    {

      @Override
      public void run()
      {
        while (true)
        {
          try
          {
            Thread.sleep(2000);
          }
          catch (InterruptedException e)
          {
            e.printStackTrace();
          }

          Runnable uiRunnable = () -> {
            DSCXPSStatusInformation dsi = xpsService.getDSCXPSStatusInformation();

            totalSpaceLabel.setValue(String.valueOf(dsi.getTotalSpaceInMB()) + " MB");
            spaceLeftLabel.setValue(String.valueOf(dscxpsStatusInformation.getLeftSpaceInMB()) + " MB");
            uptimeLabel.setValue(String.valueOf(dscxpsStatusInformation.getUptimeInSec()) + " sec");
          };

          UI.getCurrent().access(uiRunnable);
          UI.getCurrent().push();
        }
      }
    }).start();

Please read the section about Push in the book of vaadin 请阅读vaadin书中有关Push的部分

You need to enable push, so the webserver can inform the webbrowser about changes in the UI. 您需要启用推送,以便Web服务器可以将有关UI更改的信息通知Web浏览器。

I've found the answer: I am using dscxpsStatusInformation instead of dsi . 我找到了答案:我使用的是dscxpsStatusInformation而不是dsi I don't know why there is no error in eclipse. 我不知道为什么月食没有错误。 I don't have dscxpsStatusInformation anywhere in this class. 我在dscxpsStatusInformation任何地方都没有dscxpsStatusInformation

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

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