My home page has a congratulation box (let’s say, like
www.JavaBlackBelt.com/Home.wwa ), listing items (like users getting a new belt color). Every few minutes, there is a new item created in the DB that should appear in that list.
In a usual web application, the server rebuilds the html from the DB data every time a user requests the home page.
In Vaadin, the server rebuilds the html from UI Components stored in the session (Application). These are not refreshed from the DB.
I would like to avoid the following scenario: the user displays the home page, he does something else for one hour. He comes back and refresh the home page, but see 1 hour old data (because the DB is not re-queried).
My question is simple: when the user hits the browser reload button, I want my congratulation box component to be notified, so it can rebuild itself (query the DB and change the UI components) before Vaadin is producing the html for the browser.
Does the solution have something to do with Paintable?
transactionStart is a nice idea, however, Im not sure if a, say, label’s caption will be updated on transactionStart, chanes will propagate to client in this transaction. Need to check.
what about having a common single thread at the server side, which will query database from time to time and update all application instances with a new data (and application instance will update label’s caption, etc.) so client will see new data on next page reload or any other UI activity ?
The thread can be started on webapp start and stopped on webapp death events, for instance.
how can we use a single thread on the server side to update the application? using a timer to do periodic update without requests from the clients?? please elaborate on your concept if possible.
I assume you want to update the application on client side, right? Because of the HTTP protocol design, you cannot send data to the browser without a request of it. Instead, you should use a poller on client side.
Either you add an invisible ProgressBar to your application, which polls for example every 10 seconds. When polling, all changes on the server-side will be commited to the client-side. This is a bit of a hack.
You could also have a look at the “refresher” in
this thread . That’s what i did (but i couldn’t test it yet). But then you need to compile the widget yourself.
The idea to update the UI state (labels, etc) of an application controls. They’re all stored in the session at the server side, so nothing prevents you to launch a single (per webapp) thread that will periodically get all instances of the specific vaadin application and using application exposed interface provide data updates for the UI, say, updated stock quotes. Once , say, label is updated, it’s visual state will be delivered to the client on next data communication, which may be caused by another UI actions at client’s side or simple browser refresh. This will solve John’s question (I assume, he do not want to use a progress indicator at client side to minimize constant traffic from a client, however, with such progress indicator pattern, server thread will be needed anyway, this way, clients state will be just updated automatically without any user actions or refreshes)
Well, in this case, this idea seems to me a better one, if requesting new data from a datasource does not tale a lot of time. And this also eliminates any threads at the server