Selecting items in a table while updating in a background thread

Hello,

I have a Table that is updated through a background thread. I’m using the UI polling to regularly update the client and the background thread checks for new data and refills the container in an interval. The container is refilled using UI.access

I have to remove all items and add all items because I can’t just find out what has changed without parsing the whole list of items. I don’t just reset the container because I want to keep filters and sorting.

I’m using a BeanContainer with an ID-Property so that when the “new” items arrive, the items with the same ID are still selected in the table.

Now I have the following problem: If the user selects an item in the table the moment it is being updated, the selection is ignored. In fact, the other items are deselected too. Instead, I would expect one of the following two things to happen:

  1. The click goes through, so that the new item is selected, with respect to multiselect/singleselect mechanics.

  2. The click is ignored, so that the same items as before the update are selected.

I would prefer optiön 1, but I also could live with 2. Is there any way I could achieve this or is this maybe a bug?

Hello,

I recently had the same problem. I did not find a way to get rid of this UI glitch.
I finally had to change the behavior :

  • background thread is updating database (no more interraction with the container)
  • A poll listener is active on UI that makes the container refresh.
  • Make a getValue / setValue on the table around the container refresh (obviously if the user make a selection when the poll is running, unwanted multiselection happen)

As I use polling, don’t think (but not absolutely sure) VaadinSession#lock() / unlock should be used.

This workaround implies that you backend your data with a db and that you’re running Vaadin>=7.2 (PollListener is quite recent)

Regards
Sebastien

Hello Sebastien,

Thanks you for your answer.

I tried using a getValue / setValue approach in my container refresh during the background update. It improves the functionality a bit, but the glitch still happens. I’m not sure how this differs from your poll listener refresh. It seems that it just changes the time when the container is refreshed, which in my case would make matters worse, because the UI polling happens more often (1 second interval) than the update polling (interval configurable by user, but at least a couple of seconds).

Regards

Matthias

IMHO main difference is that when background process does update the container, client is no more up to date, so it’s somehow marked as dirty/out-of-sync. So next user action in UI is not treated. Server forces then ui update. In the meantime, user’s click on table is lost. Could it be considered as a bug… ? May be as, in my experience, other events are not lost (click on button, change tab), only table item click.

When moving update in the polling event, all changes are made server-side then sent back to browser, so there’s no sync issue with client-side.

Regards