开发者

How can I force Vaadin v8 to update the screen?

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.


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


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();
   }
}


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());


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).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜