Page 1 of 1

Web Environment - Force client refresh

PostPosted: Wed Mar 04, 2020 2:56 pm
by nobrega
Hi,

We're trying to add a component to the web interface to display information on long running tasks. We've added a button to the toolbar (as described here https://doc.sibvisions.com/vaadin/custo ... lication?s[]=toolbar), this button will display small label with the number of running tasks and a tooltip with a short description for each task running. If the user presses the button a screen is open with more information on running tasks.

This seems to work correctly, we already have a prototype working. Now we need a mechanism to refresh this information from time to time.

For this we are trying to use getFactory().invokeInThread after user login and on this thread pool the server from time to time. The problem is that this sees to update the text/tooltip of the menu button on server side only. The status of the button only gets refreshed on the client side when user opens a new screen/etc.

Is there any way on server side to force a client side refresh of a component?

Thanks for the help.
N.

Re: Web Environment - Force client refresh

PostPosted: Thu Mar 05, 2020 9:24 am
by Support@SIB
Yes, this is possible. But you need websockets enabled in your application server and you should use a newer application server version, e.g. Tomcat 8, 8.5, 9

Be sure that your web.xml contains:

Syntax: [ Download ] [ Hide ]
<init-param>
  <param-name>pushmode</param-name>
  <param-value>automatic</param-value>
</init-param>
       
<async-supported>true</async-supported>

for the servlet VaadinServlet.

In your code, use e.g.

Syntax: [ Download ] [ Hide ]
UIComponent.invokeInThread(new Runnable()
{
    public void run()
    {
        try
        {
            while (butThread.isSelected())
            {
                Thread.sleep(2000);
           
                System.out.println("SLEEP is over");

                UIComponent.invokeLater(new Runnable()
                {
                    public void run()
                    {
                        butThread.setImage(UIImage.getImage(UIImage.SEARCH_LARGE));
                    }
                });
               
                Thread.sleep(1000);

                UIComponent.invokeLater(new Runnable()
                {
                    public void run()
                    {
                        butThread.setImage(imgCheckNo);
                    }
                });
            }
        }
        catch (InterruptedException ie)
        {
            error(ie);
        }
    }
});

The important thing here is invokeLater. The example changes the image of a toggle button while the button is selected.

Re: Web Environment - Force client refresh

PostPosted: Thu Mar 05, 2020 7:39 pm
by nobrega
Hi,

Thanks for the help, we managed to make it work using your instructions.