Web Environment - Force client refresh
3 posts
• Page 1 of 1
Web Environment - Force client refresh
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.
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: 19
- Joined: Tue Feb 11, 2020 6:40 pm
Re: Web Environment - Force client refresh
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:
for the servlet VaadinServlet.
In your code, use e.g.
The important thing here is invokeLater. The example changes the image of a toggle button while the button is selected.
Be sure that your web.xml contains:
<init-param>
<param-name>pushmode</param-name>
<param-value>automatic</param-value>
</init-param>
<async-supported>true</async-supported>
<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.
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);
}
}
});
{
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.
-
Support@SIB - Posts: 353
- Joined: Mon Sep 28, 2009 1:56 pm
Re: Web Environment - Force client refresh
Hi,
Thanks for the help, we managed to make it work using your instructions.
Thanks for the help, we managed to make it work using your instructions.
- nobrega
- Posts: 19
- Joined: Tue Feb 11, 2020 6:40 pm
3 posts
• Page 1 of 1