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.

Johannes Rabauer
  • 330
  • 3
  • 15
Valyrion
  • 2,342
  • 9
  • 29
  • 60

5 Answers5

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

Charles Anthony
  • 3,155
  • 17
  • 21
  • 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 accepted – Valyrion Sep 30 '11 at 10:23
6

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();
   }
}
rmv
  • 3,195
  • 4
  • 26
  • 29
Thomas
  • 1,622
  • 17
  • 24
  • 1
    How to enable server pushes? – Alex78191 Feb 25 '19 at 15:29
  • @Alex78191 To enable server pushes you have to add `@Push` to a class extending UI, see [official documentation](https://vaadin.com/docs/v8/framework/advanced/advanced-push.html) 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) – Inmer Feb 15 '21 at 16:02
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());
Phil
  • 35,852
  • 23
  • 123
  • 164
Marthin
  • 6,413
  • 15
  • 58
  • 95
2

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

Ryan Schipper
  • 1,019
  • 7
  • 8
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.

user2310395
  • 297
  • 3
  • 6