When and how to update the UI?

Hi,

having played with Vaadin a bit (nothing serious), I noticed the following:

  1. I cannot apply arbitrarily updates to the UI and assume the Browser to know. For example, I have added components to a vertical layout, which was already displayed, and nothing happened.
  2. On the other hand, in general I seem to be able to apply updates: For example, the Wizards for Vaadin addon does just that, and the sample application works for me. (After studying the sources, that seems to be because it uses Panel.setContent(Component), which seems to be somewhat special.)

Now, my question would be: Can anyone explain the logic behin? Which updates would work, and which don’t?

Thanks very much,

Jochen

Hi Jochen,

Yes, you can add components to vertical layout and expect those to be updated on browser. Could you share your code? Maybe the problem is somewhere else.

Basically, updates that are done while handling a client request (most often triggered by a UI event) will be communicated to the client when the response is sent. This is the most common scenario. Normally, if you do asynchronous updates in a thread that’s not currently handling a request, those updates cannot be communicated to the client before the next request. This is simply how HTTP works. However, in Vaadin 7.1 you can enable server push to allow true asynchronous updates, or you can use
UI.setPollInterval
to make the client poll the server for updates at regular intervals.

So, the answer to your question is:

  • When sending a response after handling a client event
  • When releasing the session lock after asynchronous access and automatic push is enabled
  • When calling
    UI.push
    inside asynchronous access and manual push is enabled
  • When the client sends a poll request and polling is enabled

If you think you’re correctly doing one of these and the updates still aren’t shown, please describe your problem in more detail and provide a code sample like Jarno said.

Are you by any chance trying to perform updates e.g. in a background thread rather than when handling UI events. If so, you need to use server push or polling for the UI to get the updates.

Thanks very much for the clarification, Johannes! As you wrote: That’s how HTTP works, so I wasn’t really expecting things to work. Your reply will help me in the future.