How can I force Vaadin v8 to update the screen?
Asked Answered
A

5

17

I have a small Vaadin v8 application that has several input fields (comboboxes, selectgroups, etc...). The content of most of these is determined by the chosen content of the first ComboBox. However, when I select something in it, all the others stay blank until I click one, at which point they all update. This is not desired behaviour, but I assume it's being caused by the server-side being up to date but not updating the client side view. (Even when adding requestRepaint() in my first Combobox's ValueChangeListener)

There must be some method to force Vaadin to get the data I want it to display even if no other components are clicked?

EDIT I'm not allowed to post answers to my own question so soon, so I'm putting it here temporarily:

I found that there's a javascript method that synchs client and server.

myComponent.getApplication().getMainWindow().executeJavaScript("javascript:vaadin.forceSync();");

The only problem I have now is that the ValueChangeListener on one of my comboboxes still only fires when I click another combobox (or the same one twice). It's the weirdest thing because the second combobox, when loaded, fires it's event perfectly.

Aegrotat answered 30/9, 2011 at 8:15 Comment(0)
T
18

Is the first ComboBox in "immediate" mode?

If not, it probably should be : component.setImmediate(true).

See https://vaadin.com/book/-/page/components.selection.html

Timbre answered 30/9, 2011 at 10:15 Comment(1)
That fixed it, can't believe I missed that since I already had the other one set up correctly. I'll just leave my answer in my post and select this one as acceptedAegrotat
A
7

I had the same problem, see below how it could be done in version 8.0.5 (from 2017):

@Push
public class WebUi extends UI {
   public void fireComponentUpdated() {
      getUI().push();
   }
}
Ander answered 30/11, 2017 at 0:8 Comment(2)
How to enable server pushes?Disadvantaged
@Disadvantaged To enable server pushes you have to add @Push to a class extending UI, see official documentation for full details (I know that for Alex may not be useful since I am answering 2 year later, but for anyone stuck on this)Standfast
I
4

There is a hack you can use if you have set a datasource for your componets that forces vaadin to re-render them. I use this for updating tables that have dynamic data

yourcomponent.setContainerDataSource(yourcomponent.getContainerDataSource());
Illfavored answered 30/9, 2011 at 8:28 Comment(1)
Eww. =) I'm surprised that case hasn't been optimised out by the dev team yet.Ardoin
A
3

Did you requestRepaint on the correct components?

Keep in mind that requestRepaint marks the component as dirty but doesn't mean it will be repainted - a client can only be refreshed when it makes a request to the server.

See this thread https://vaadin.com/forum/-/message_boards/view_message/231271 for more information about your options (it deals with UI refreshes due to background thread processing).

Ardoin answered 30/9, 2011 at 8:31 Comment(0)
S
1

In Vaadin 7 it is enough to put this line in main UI.init(VaadinRequest) method:

UI.getCurrent().setPollInterval( 1000 );

if you want to refresh your UI (in this case) every second. This way you instruct UI to poll server for changes in defined interval.

Beware, excessive server traffic might be a problem if you have lot of users that use your application at the same time.

In Vaadin 6 you will have to play with ProgressIndicator (which could be invisible if you want) and try to do the similar what UI.getCurrent().setPollInterval(int) in Vaadin 7 does.

Sanjuana answered 24/6, 2016 at 15:7 Comment(2)
Not a good idea. I'd recomend enabling server pushes for this purpose. Although this doesn't seem to be the OP problem.Forras
@Forras How to enable server pushes?Disadvantaged

© 2022 - 2024 — McMap. All rights reserved.