簡體   English   中英

Vaadin UI從其他線程更改UI組件時未更新

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

我在普通的私有函數中有以下代碼片段,該代碼片段是從同一類的另一種方法調用的(該類稱為AdministrationComponent ,它extends CustomComponent )。 此組件已添加到TabBarView 我的問題是,您在代碼中看到的三個標簽沒有更新。

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

請閱讀vaadin書中有關Push的部分

您需要啟用推送,以便Web服務器可以將有關UI更改的信息通知Web瀏覽器。

我找到了答案:我使用的是dscxpsStatusInformation而不是dsi 我不知道為什么月食沒有錯誤。 我在dscxpsStatusInformation任何地方都沒有dscxpsStatusInformation

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM