adding a component to a componentcontainer in a background thread

Hi,

I am trying to add a component to a layout in a background thread. My understanding is that something like the listing below is the correct method for manipulating the UI from a background thread. When I try this, however, the label does not get added to the layout. Some clarification would be greatly appreciated.

Thank you,

Matthew Fleming


UI ui = UI.getCurrent();
ui.access(new Runnable() {
    @Override
     public void run() {
    	Label label = new Label("hi there");
        label.setHeight("100px");
        vl.addComponent(label);
        // vl is a VerticalLayout, which is the content for the UI
    }
});


Updating UI from another Thread

Thanks very much. However, the diagnosis indicated by the link is correct, but not the fix. Instead, in Vaadin 7 you just call UI.push() after making the UI update in the background thread.

Well the thing is that this thread was made when only Vaadin 6 was out. In Vaadin 6 you had to use a poll or a push add-on like the thread says.
Now in Vaadin 7 you have the ability to use polling (UI.setPollingInterval(timeinmilliseconds)), automatic push (add @Push annotation to your UI class. Then you don’t have to do anything. updates in background-threads should get automatically pushed to the client) or manual push (add @Push(pushMode=PushMode.MANUAL) to your UI-class. Then you have to call UI.push() whenever you update something in the background)