I’m working on a new project to build an enterprise portal with Liferay and Vaadin and I’m new to Vaadin. I just went through “book of vaadin” with some examples, I have some questions about binding data to UI using container:
Is container or data in container are per http session? Or, if there are two browsers pointing to Liferay Portal with Vaadin Portlet, there would be two container objects on Server JVM, one for each browser?
Is data in container are downloaded to browser or client immediately or on demand? For example, after binding a container to a table, will data be downloaded immediately or just first “page”?
Once data is downloaded to the browser/client, if there is a data change in container, are all the data downloaded again or only diff is sent to the browser/client?
What is the best practice to propagate the data change to the browser/client? For example, if Browser A updated the data and saved in the back-end, how these change are refreshed to Browser B?
There is one instance of your Application class per user (i.e. per http session). So two users, two instances of the Application class and therefore two instances of all components and containers connected to them.
This depends on the component. A Table and a ComboBox will lazily load only the data they need (i.e. the first page + some extra buffer).
Again, depends on the component. Table will reload its whole cache which is the current page + some extra buffer.
As you are on server side all the time you can use whatever mechanism you want to notify and update the other application instance (be sure to synchronize on the application if you are performing changes in other threads) like JMS (or even shared static variables).
After the application instance has been updated on the server you will need some method to get to changes to Browser B. This can be accomplished by polling in the application in Browser B or by using one of the push add-ons from the directory. See
http://vaadin.com/forum/-/message_boards/view_message/231271 for more info on this.
I have one more follow-up question: can two UI Components share one data container at client/browser? For example, I have two child windows: one with tree and another with table, can both tree and table share one data container so change in the table will reflect in the tree window automatically?
Since data in container is sent to client/browser, in this use case, will one copy of data for both UI Components send to browser or two copies of data, one for each UI Component, send to browser?
While the Container API would permit sharing container instances between multiple UI components, in practice the default implementations don’t - how listener registration is handled by them can lead to memory leaks. In addition, sorting and filtering are done on the container level, which can also cause problems with sharing.
Some container implementations (such as the JPAContainer add-on) split the container and its underlying data provider so that the same database access layers (including caches etc.) can be shared between multiple light-weight container instances. The same pattern could be applied to other containers as well. It should not be complicated in read-only cases, but the more caching etc. there is, the more complex it gets.
Each UI component sends the necessary data to the client independently of any other components - but note that e.g. Table only sends the visible rows and a small buffer around them to make scrolling smoother, and lazily fetches more data from the server.