简体   繁体   中英

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 ). This component is added to a 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

You need to enable push, so the webserver can inform the webbrowser about changes in the UI.

I've found the answer: I am using dscxpsStatusInformation instead of dsi . I don't know why there is no error in eclipse. I don't have dscxpsStatusInformation anywhere in this class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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