This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information

Web Environment - Force client refresh

General questions regarding the development with JavaFX UI for JVx.

Web Environment - Force client refresh

Postby nobrega » Wed Mar 04, 2020 2:56 pm

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.
nobrega
 
Posts: 14
Joined: Tue Feb 11, 2020 6:40 pm

Re: Web Environment - Force client refresh

Postby Support@SIB » Thu Mar 05, 2020 9:24 am

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.
User avatar
Support@SIB
 
Posts: 345
Joined: Mon Sep 28, 2009 1:56 pm

Re: Web Environment - Force client refresh

Postby nobrega » Thu Mar 05, 2020 7:39 pm

Hi,

Thanks for the help, we managed to make it work using your instructions.
nobrega
 
Posts: 14
Joined: Tue Feb 11, 2020 6:40 pm


Return to Development