Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Vaadin Push don't work correctly
I am trying to update one Ui from another. I use spring + vaadin, when i try update ui i can't see immediately changes, until that time I click on content.
This is my main UI code
@SpringUI
@UIScope
@Title("Meduchet")
@Widgetset("DashboardWidgetSet")
@Theme("dashboard")
@Push(transport=Transport.LONG_POLLING,value=PushMode.MANUAL)
@SuppressWarnings("serial")
public class DashboardUI extends UI {
@Autowired
private DashboardEventBus eventBus;
@Autowired
private DataProvider dataProvider;
@Autowired
private Broadcaster broadcaster;
@Override
protected void init(VaadinRequest request) {
eventBus.register(this);
Responsive.makeResponsive(this);
addStyleName(ValoTheme.UI_WITH_MENU);
updateContent();
Page.getCurrent().addBrowserWindowResizeListener(new BrowserWindowResizeListener() {
@Override
public void browserWindowResized(final BrowserWindowResizeEvent event) {
eventBus.post(new BrowserResizeEvent());
}
});
}
And my View where i register to boradcaster
@SuppressWarnings({ "serial" })
public class DoctorGridView extends VerticalLayout implements View, BroadcastListener { @Override
public void receiveBroadcast() {
UI.getCurrent().access(new Runnable() {
@Override
public void run() {
List<Doctor> data=DashboardUI.getDataProvider().getDoctors();
if (data!=null){
grid.setContainerDataSource(new BeanItemContainer<Doctor>(Doctor.class,data));
}
UI.getCurrent().push();
}
});
}
public DoctorGridView() {
setSizeFull();
addStyleName("transactions");
DashboardUI.getDashboardBroadcaster().register(this);
..
}
@Override
public void detach() {
super.detach();
DashboardUI.getDashboardEventbus().unregister(this);
DashboardUI.getDashboardBroadcaster().unregister(this);
}
And my Broadcaster
@Component
@Scope(scopeName = "singleton", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class Broadcaster implements Serializable {
/**
* @author Vova
*/
private static final long serialVersionUID = 1L;
private ExecutorService executorService = Executors.newSingleThreadExecutor();
private List<BroadcastListener> listeners = new ArrayList<BroadcastListener>();
public synchronized void register(BroadcastListener listener) {
listeners.add(listener);
}
public synchronized void unregister(BroadcastListener listener) {
listeners.remove(listener);
}
public synchronized void broadcast() {
for (final BroadcastListener listener : listeners)
executorService.execute(new Runnable() {
@Override
public void run() {
listener.receiveBroadcast();
}
});
}
public interface BroadcastListener {
void receiveBroadcast();
}
}
Have you checked that UI.getCurrent() returns the right thing in receiveBroadcast()?
If I read that right, it's run in another thread, so UI.getCurrent() will probably not return the right UI.
Tom Rauchenwald: Have you checked that UI.getCurrent() returns the right thing in receiveBroadcast()?
If I read that right, it's run in another thread, so UI.getCurrent() will probably not return the right UI.